As you already know, rows in Excel are labeled with numbers, so it’s easy to get to that row by specifying a number. But it’s not that easy to go, for example, to 121st column because it’s labeled by one to three letter, so the first column is A and the last (16,384) is XFD.
In order to know, what label has the 121st column, you have to convert 121 to character label. You can achieve this by using an Excel formula.
This formula will take the numerical value from A2 and returns it as a column label. Let’s autofill this formula for the rest of the cells.
The formula works, but it’s quite complicated. Let’s create a function that we can call from the inside the worksheet, which takes only one parameter.
This VBA function gets one parameter, which indicated the column number, and returns label from A(1) to XFD(16,384). If the number is larger, it returns False.
Function NumbersToColumns(myCol As Integer)
If myCol >= 1 And myCol <= 16384 Then
iA = Int((myCol - 1) / 26)
fA = Int(IIf(iA - 1 > 0, (iA - 1) / 26, 0))
NumbersToColumns = IIf(fA > 0, Chr(fA + 64), "") & _
IIf(iA - fA * 26 > 0, _
Chr(iA - fA * 26 + 64), "") & _
Chr(myCol - iA * 26 + 64)
NumbersToColumns = False
As you can see, the VBA function also works.