Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default 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,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default 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,

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default 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,


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get Column Letter BB Ivan Excel Discussion (Misc queries) 7 January 30th 09 11:50 PM
How do I turn excel columns from column number to column letter? column Setting up and Configuration of Excel 1 April 29th 08 10:15 AM
How to replace column letter in refferences with a function using the old column letter? Dmitry Kopnichev Links and Linking in Excel 6 October 13th 05 09:09 AM
How to replace column letter in refferences with a function using the old column letter? Dmitry Kopnichev Excel Worksheet Functions 6 October 13th 05 09:09 AM
column header changed from letter to number, how return to letter Ron Excel Discussion (Misc queries) 2 May 9th 05 08:34 PM


All times are GMT +1. The time now is 07:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"