Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Have Excel Tell Me Active Cell Details 2

Status
Not open for further replies.

MattGreer

Technical User
Feb 19, 2004
471
0
0
US
So I was working on a little task yesterday (thanks Skip!) and I was trying to figure it out on my own. Always fun.

One thing I was trying to get Excel to do was to tell me what column the "focus" was in, or rather what column number the activecell was. I couldn't. I found this on the support site but I wasn't able to make it work:

So, simply, what would be the VBA syntax to get a message box that says "I'm in Column " & intColumnNumber

Same case, what about the row?

The answer is probably in that link but I'm just not capable of interpreting how to implement it correctly. :(

Thanks!!


Matt
 
try
Dim r As Range

Set r = ActiveCell 'note use of Set keyword as assigning an Object ref!

MsgBox r.Column & Chr(r.Row + 64)'this will work till column z
 
better

Code:
Dim r As Range

Set r = ActiveCell   'note use of Set keyword as assigning an Object ref!

MsgBox Replace(r.Address, "$", "")
 
I think PWise got is backwards (in his first post), and Matt wants the numbers for Column / Row:

Code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

MsgBox "I am in Column " & ActiveCell.Column & " Row " & ActiveCell.Row
   
End Sub

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Geez I feel dumb, lol. Thanks guys. :)



Thanks!!


Matt
 
FYI...
Code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   With Target
      MsgBox "I am in Column " & .Column & " Row " & .Row & " I have " & _
             .Columns.Count & " column(s) selected and " & _
             .Rows.Count & " row(s) selected"
   End With
End Sub

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I realize you asked for the information in a message box but on the off-chance you're not aware of these options:
[ol][li]The column and row can be seen on the Name Box on the Formula Bar[/li]
[li]Application.StatusBar = "use Skip's text value here..."[/li][/ol]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top