Does anyone have an Excel VBA function which can return the column letter(s) from a number?
For example, entering 100 should return CV
.
Does anyone have an Excel VBA function which can return the column letter(s) from a number?
For example, entering 100 should return CV
.
Furthering on brettdj answer, here is to make the input of column number optional. If the column number input is omitted, the function returns the column letter of the cell that calls to the function. I know this can also be achieved using merely
ColumnLetter(COLUMN())
, but i thought it'd be nice if it can cleverly understand so.The trade off of this function is that it would be very very slightly slower than brettdj's answer because of the
IF
test. But this could be felt if the function is repeatedly used for very large amount of times.Cap A is 65 so:
MsgBox Chr(ActiveCell.Column + 64)
Found in: http://www.vbaexpress.com/forum/showthread.php?6103-Solved-get-column-letter
Here is a simple one liner that can be used.
It will only work for a 1 letter column designation, but it is nice for simple cases. If you need it to work for exclusively 2 letter designations, then you could use the following:
Column letter from column number can be extracted using formula by following steps
1. Calculate the column address using ADDRESS formula
2. Extract the column letter using MID and FIND function
Example:
1. ADDRESS(1000,1000,1)
results $ALL$1000
2. =MID(F15,2,FIND("$",F15,2)-2)
results ALL asuming F15 contains result of step 1
In one go we can write
MID(ADDRESS(1000,1000,1),2,FIND("$",ADDRESS(1000,1000,1),2)-2)
This is a version of robartsd's answer (with the flavor of Jan Wijninckx's one line solution), using recursion instead of a loop.
I've tested this with the following inputs: