![]() |
Column letter
Need some handy vba code to loop through the columns of a worksheet and
identify which column letter I am currently in, rather than the column number. Any ideas. Thanks, |
Column letter
Hi,
Here are 2 function that do that in a different way. One take the column number a parameter, the other one takes the cell as parameter. '-------------------------------------------------------------- Function ColChar(i As Long) As String ColChar = IIf(i 26, Chr((i - 1) \ 26 + 64), "") & _ Chr((i - 1) Mod 26 + 65) End Function Function colChar2(cell As Range) As String colChar2 = cell.Parent.Cells(1, cell.Cells(1).Column).Address(False, False) colChar2 = Left(colChar2, Len(colChar2) - 1) End Function '------------------------------------------------------------------ -- Regards, Sébastien <http://www.ondemandanalysis.com "Steve" wrote: Need some handy vba code to loop through the columns of a worksheet and identify which column letter I am currently in, rather than the column number. Any ideas. Thanks, |
Column letter
This will convert the column number to the letter(s):
Function Number2Letter(ByVal n As Long) As String 'returns the Excel sheet column letter given a number '---------------------------------------------------- If n 0 And n < 257 Then Number2Letter = Split(Cells(n).Address, "$")(1) Else Number2Letter = Error(9) ' Subscript out of range End If End Function I take you know how to get the column number of the active cell. RBS "Steve" wrote in message ... Need some handy vba code to loop through the columns of a worksheet and identify which column letter I am currently in, rather than the column number. Any ideas. Thanks, |
All times are GMT +1. The time now is 03:33 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com