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


Hi folks.

First time here, hope you can help me.

I'm trying to get a index on a for each next routine but I don't know
how to do it. Like the Item method. In the example I want the statement
to run on the last cell of the selection.

Example:

Sub Example()
For each cell in selection

if cell.index = selection.count then
statement
endif

next

end sub

Thanks for any help you can give.

Best regards,
KiO


--
[KiO] ASamarcos
------------------------------------------------------------------------
[KiO] ASamarcos's Profile: http://www.excelforum.com/member.php...o&userid=37554
View this thread: http://www.excelforum.com/showthread...hreadid=571874

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Index on a selection

If it's a single area:

dim MyLastCell as range

with selection
set mylastcell = .cells(.cells.count)
end with

No need to loop through all the cell.

"[KiO] ASamarcos" wrote:

Hi folks.

First time here, hope you can help me.

I'm trying to get a index on a for each next routine but I don't know
how to do it. Like the Item method. In the example I want the statement
to run on the last cell of the selection.

Example:

Sub Example()
For each cell in selection

if cell.index = selection.count then
statement
endif

next

end sub

Thanks for any help you can give.

Best regards,
KiO

--
[KiO] ASamarcos
------------------------------------------------------------------------
[KiO] ASamarcos's Profile: http://www.excelforum.com/member.php...o&userid=37554
View this thread: http://www.excelforum.com/showthread...hreadid=571874


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Index on a selection


Hi Peterson.

Thanks for your help, but I actually want a way to see the index of the
cell that is being processed by the for each next routine.

Imagine that Selection.Count gives me 40. 40 cells in the range I
selected.

When the For Each starts I want to know, on each step, where the count
is. Is it 1, 2, 37?

I thought the Cell.Index could give me the answer but returns a error
message and I think theres a better way to do that than to put a
counter on it.

Best Regards,
KiO


--
[KiO] ASamarcos
------------------------------------------------------------------------
[KiO] ASamarcos's Profile: http://www.excelforum.com/member.php...o&userid=37554
View this thread: http://www.excelforum.com/showthread...hreadid=571874

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Index on a selection

I don't think that there's a better way to do than to count the cells yourself.

But you do have a few choices.

You could do:

dim myRng as range
dim myCell as range
dim iCtr as long

ictr = 0
set myrng = range("c5:e12")
for each mycell in myrng.cells
ictr = ictr + 1
msgbox ictr & "--" & mycell.address(0,0)
next mycell

to see how the "pattern" that mycell takes.

=============

or you could loop through the columns of the range:

dim myRng as range
dim myCol as range
dim myCell as range
dim iCtr as long

ictr = 0
set myrng = range("c5:e12")
for each mycol in myrng.columns
for each mycell in mycol.cells
ictr = ictr + 1
msgbox ictr & "--" & mycell.address(0,0)
next mycell
next mycol

And see that pattern.

The same kind of thing to loop through each row.

"[KiO] ASamarcos" wrote:

Hi Peterson.

Thanks for your help, but I actually want a way to see the index of the
cell that is being processed by the for each next routine.

Imagine that Selection.Count gives me 40. 40 cells in the range I
selected.

When the For Each starts I want to know, on each step, where the count
is. Is it 1, 2, 37?

I thought the Cell.Index could give me the answer but returns a error
message and I think theres a better way to do that than to put a
counter on it.

Best Regards,
KiO

--
[KiO] ASamarcos
------------------------------------------------------------------------
[KiO] ASamarcos's Profile: http://www.excelforum.com/member.php...o&userid=37554
View this thread: http://www.excelforum.com/showthread...hreadid=571874


--

Dave Peterson
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
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
First row in Selection range (first index of a cell) EXCEL VBA [email protected] Excel Programming 1 March 20th 06 02:01 PM
Index of Cells in a selection Rod[_6_] Excel Programming 4 November 16th 03 10:35 AM
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 08:42 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"