|
-
Apr 7th, 2004, 08:16 AM
#1
Thread Starter
Fanatic Member
Excel - Return column alphabet from column number
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:
Code:
Function GetAlphabet(ByVal ColumnNumber as Long) as String
which if I call must say:
Output: "A"
-
Apr 7th, 2004, 08:32 AM
#2
No built-in function as far as I know, but here's a function I wrote:
VB Code:
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
-
Apr 7th, 2004, 09:20 AM
#3
Thread Starter
Fanatic Member
-
Nov 18th, 2008, 03:46 PM
#4
New Member
Re: Excel - Return column alphabet from column number
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
-
Nov 18th, 2008, 04:04 PM
#5
Re: Excel - Return column alphabet from column number
columns(1).address will return $A:$A
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|