PDA

Click to See Complete Forum and Search --> : Excel - Return column alphabet from column number


Sathyaish
Apr 7th, 2004, 08:16 AM
Is there some function in Excel (VBA) that will get me the column alphabet if I provide the column number, or do I have to write one. I ask because I know that there is, yet I recall I wrote this functionality for the previous application, and I don't want to:

(1) Reuse it, if there's something in-built
(2) Re-invent the wheel

Help!

PS: I'm looking for something like:


Function GetAlphabet(ByVal ColumnNumber as Long) as String


which if I call must say:


GetAlphabet(1)


Output: "A"

si_the_geek
Apr 7th, 2004, 08:32 AM
No built-in function as far as I know, but here's a function I wrote:

Function xl_Col(ByRef Col_No) As String
'returns Excel column name from value
'(eg: col_no 27 returns "AA")
'Only allow valid columns
If Col_No < 1 Or Col_No > 256 Then Exit Function

If Col_No < 27 Then 'Single letter
xl_Col = Chr(Col_No + 64)
Else 'Two letters
xl_Col = Chr(Int((Col_No - 1) / 26) + 64) & _
Chr(((Col_No - 1) Mod 26) + 1 + 64)
End If

End Function

Sathyaish
Apr 7th, 2004, 09:20 AM
Thank you so much.

nnebeel
Nov 18th, 2008, 02:46 PM
Another way:
If you only need to return the letter number of columns A-Z in an Excel 2003 Spreadsheet:
Use the CHAR() function:

=char(64+column())

Let me know if this helps :)

westconn1
Nov 18th, 2008, 03:04 PM
columns(1).address will return $A:$A