Type the formula =SpellNumber(A1) into the cell where you want to display a written number, where A1 is the cell containing the number you want to convert. You can also manually type the value like =SpellNumber(22.50). Press Enter to confirm the formula.
Basic Formula - Works for A to Z You just have to input the number for the column directly in the formula. The CHAR() function gets a letter based on its number as defined by the character set of your computer; though, you don't need to know that to use this function.
Do-While Loop is another way to convert column number to letter in VBA Excel. Similarly, call the UDF in the dataset, pass the cell reference number as the argument, press Enter and drag the row to convert the column number to letter in Excel with the Do-While Loop in VBA.
This function returns the column letter for a given column number.
Function Col_Letter(lngCol As Long) As String
Dim vArr
vArr = Split(Cells(1, lngCol).Address(True, False), "$")
Col_Letter = vArr(0)
End Function
testing code for column 100
Sub Test()
MsgBox Col_Letter(100)
End Sub
If you'd rather not use a range object:
Function ColumnLetter(ColumnNumber As Long) As String
Dim n As Long
Dim c As Byte
Dim s As String
n = ColumnNumber
Do
c = ((n - 1) Mod 26)
s = Chr(c + 65) & s
n = (n - c) \ 26
Loop While n > 0
ColumnLetter = s
End Function
Something that works for me is:
Cells(Row,Column).Address
This will return the $AE$1 format reference for you.
MsgBox Columns( 9347 ).Address
returns .To return ONLY the column letter(s): Split((Columns(
Column Index
).Address(,0)),":")(0)
MsgBox Split((Columns( 2734 ).Address(,0)),":")(0)
returns .
And a solution using recursion:
Function ColumnNumberToLetter(iCol As Long) As String
Dim lAlpha As Long
Dim lRemainder As Long
If iCol <= 26 Then
ColumnNumberToLetter = Chr(iCol + 64)
Else
lRemainder = iCol Mod 26
lAlpha = Int(iCol / 26)
If lRemainder = 0 Then
lRemainder = 26
lAlpha = lAlpha - 1
End If
ColumnNumberToLetter = ColumnNumberToLetter(lAlpha) & Chr(lRemainder + 64)
End If
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With