Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do I get the column of a cell?

Range("B5").Select
? Left(ActiveCell.Columns.Address(, ColumnAbsolute:=False), 1)
B
Range("BB5").Select
? Left(ActiveCell.Columns.Address(, ColumnAbsolute:=False), 1)
B

--
Regards,
Tom Ogilvy

"debartsa" wrote in message
...
Thanks Carim,

I'll give it a try!


"Carim" wrote in message
oups.com...

Hi Sam,

Why don't you just add Left(x,1)
Left(Target.Columns.Address(, ColumnAbsolute:=False), 1)

HTH
Cheers
Carim





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default How do I get the column of a cell?

Here's one possible solution using mod arithematic:

Sub GetSelectedColumn()

Dim iCol As Integer
Dim sCol As String

iCol = ActiveCell.Column

If iCol 26 Then
sCol = Chr(Int(iCol / 26) + 64) & Chr((iCol Mod 26) + 64)
Else
sCol = Chr(iCol + 64)
End If
MsgBox sCol

End Sub

Notes:
- Excel's columns go from A = 1 to IV = 256
- The Chr() function returns the character for a given ASCII value,
where Chr(65) = 'A', Chr(66) = 'B', etc.
- Int() truncates a division to the integer portion and Mod gives the
remainder of the dision operation. These two values are then used to
get the 1st and 2nd column identifiers.

--Nick

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
Maddening Dilemma - Compare each cell within column a to each cell in column b and find unique matches [email protected] Excel Worksheet Functions 66 May 1st 23 03:44 AM
Sum Cell Values of one column based on Another Cell Value in a different column kristenb via OfficeKB.com Excel Worksheet Functions 5 April 26th 23 07:41 PM
compare cells in column to criteria, then average next column cell Bradwin Excel Worksheet Functions 2 July 21st 08 08:37 PM
Need the formula or macro. If i enter today date in the cell (Row 1,Column 2) and on tab out, the column 1 cell should be filled with "corresponding Day" of the date kakasay Excel Discussion (Misc queries) 1 January 22nd 07 12:31 PM
Format cell in column B based on value in the next cell (column c) Nicole Excel Discussion (Misc queries) 7 May 18th 05 10:19 PM


All times are GMT +1. The time now is 08:29 PM.

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"