ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel - Return column alphabet from column number (https://www.excelbanter.com/excel-programming/294434-excel-return-column-alphabet-column-number.html)

Sathyaish

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:


code:--------------------------------------------------------------------------------
GetAlphabet(1)
--------------------------------------------------------------------------------


Output: "A"

Tom Ogilvy

Excel - Return column alphabet from column number
 
activecell.Address

will give you row and column.

to get just the column

Left(activecell.Address(0,0), 1 +(-1*(activecell.Column 26)))

or
Left(activecell.Address(0,0), 2 + (activecell.Column <= 26))

--
Regards,
Tom Ogilvy


"Sathyaish" wrote in message
om...
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:



code:-----------------------------------------------------------------------
---------
GetAlphabet(1)
--------------------------------------------------------------------------

------


Output: "A"




Chip Pearson

Excel - Return column alphabet from column number
 
Try a function like the following:

Function ColLetter(ColNumber As Integer) As String
ColLetter = Left(Cells(1, ColNumber).Address(False, False), _
1 - (ColNumber 26))
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Sathyaish" wrote in message
om...
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:



code:-----------------------------------------------------------------------
---------
GetAlphabet(1)
--------------------------------------------------------------------------

------


Output: "A"





All times are GMT +1. The time now is 08:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com