Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Index of Cells in a selection


Hello, everyone

I am trying to write code to determine the index of the "active" cell in a selection of say, two cells. Can you direct me to the way of learning how to go about that

I appreciate your time

Rod
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Index of Cells in a selection

Hello Rod

Here's one way:

Sub FindIndex()
'Leo Heuser, 14 Nov. 2003
Dim Cell As Range

For Each Cell In Selection.Cells
If Cell.Address = ActiveCell.Address Then
MsgBox "Index = " & Cell.Row - Selection.Row + 1 _
& ", " & Cell.Column - Selection.Column + 1
Exit For
End If
Next Cell

End Sub


--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"Rod" skrev i en meddelelse
...

Hello, everyone!

I am trying to write code to determine the index of the "active" cell in a

selection of say, two cells. Can you direct me to the way of learning how
to go about that?

I appreciate your time,

Rod



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Index of Cells in a selection

Ranges don't really have indexes. Are the cells contiguous?

What are you actually trying to do?

--
Regards,
Tom Ogilvy

"Rod" wrote in message
...

Hello, everyone!

I am trying to write code to determine the index of the "active" cell in a

selection of say, two cells. Can you direct me to the way of learning how
to go about that?

I appreciate your time,

Rod



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Index of Cells in a selection

First, this is no criticism of Leo who offered an excellent intepretation of
a vague question and offered an excellent suggesgted solution.

To the Original Poster,
Just curious. That gives you something like the offset from the first cell
in the range.

For example, select F8, then hold down the control key and select C3, so C3
is the active cell. Then run the macro. Is that what you were asking for?

--
Regards,
Tom Ogilvy


"Leo Heuser" wrote in message
...
Hello Rod

Here's one way:

Sub FindIndex()
'Leo Heuser, 14 Nov. 2003
Dim Cell As Range

For Each Cell In Selection.Cells
If Cell.Address = ActiveCell.Address Then
MsgBox "Index = " & Cell.Row - Selection.Row + 1 _
& ", " & Cell.Column - Selection.Column + 1
Exit For
End If
Next Cell

End Sub


--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"Rod" skrev i en meddelelse
...

Hello, everyone!

I am trying to write code to determine the index of the "active" cell in

a
selection of say, two cells. Can you direct me to the way of learning how
to go about that?

I appreciate your time,

Rod





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Index of Cells in a selection

Thanks, Tom, but I'm afraid, this is a case,
where I didn't see the forest for the trees :-(

Sub FindIndex()

MsgBox "Index = " & ActiveCell.Row - Selection.Row + 1 _
& ", " & ActiveCell.Column - Selection.Column + 1

End Sub

does exactly the same.

LeoH


"Tom Ogilvy" skrev i en meddelelse
...
First, this is no criticism of Leo who offered an excellent intepretation

of
a vague question and offered an excellent suggesgted solution.

To the Original Poster,
Just curious. That gives you something like the offset from the first cell
in the range.

For example, select F8, then hold down the control key and select C3, so

C3
is the active cell. Then run the macro. Is that what you were asking

for?

--
Regards,
Tom Ogilvy


"Leo Heuser" wrote in message
...
Hello Rod

Here's one way:

Sub FindIndex()
'Leo Heuser, 14 Nov. 2003
Dim Cell As Range

For Each Cell In Selection.Cells
If Cell.Address = ActiveCell.Address Then
MsgBox "Index = " & Cell.Row - Selection.Row + 1 _
& ", " & Cell.Column - Selection.Column + 1
Exit For
End If
Next Cell

End Sub


--
Best Regards
Leo Heuser

Followup to newsgroup only please.




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
cells selection Davey Excel Worksheet Functions 7 April 22nd 09 06:27 PM
Copy Selection - Transpose Selection - Delete Selection Uninvisible Excel Discussion (Misc queries) 2 October 23rd 07 04:18 PM
First row in Selection range (first index of a cell) EXCEL VBA [email protected] Excel Worksheet Functions 1 March 20th 06 09:38 PM
How do I shade cells during selection? MysterTLC Excel Worksheet Functions 1 June 3rd 05 03:48 PM
Index of cells in a selection Rod[_6_] Excel Programming 0 November 14th 03 09:01 PM


All times are GMT +1. The time now is 10:36 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"