Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Cycling through the cells in a range

Can someone tell me how to cycle through the cells in a
range that has more than one cell selected?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Cycling through the cells in a range

for each cell in Selection
msgbox cell.Address
Next

--
Regards,
Tom Ogilvy

"Wandering mage" wrote in message
...
Can someone tell me how to cycle through the cells in a
range that has more than one cell selected?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Cycling through the cells in a range

Thank you.
-----Original Message-----
for each cell in Selection
msgbox cell.Address
Next

--
Regards,
Tom Ogilvy

"Wandering mage"

wrote in message
...
Can someone tell me how to cycle through the cells in a
range that has more than one cell selected?



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Cycling through the cells in a range

Wandering mage wrote:

Can someone tell me how to cycle through the cells in a
range that has more than one cell selected?

For i = 1 To Selection.Count
MsgBox Selection(i).Address
Next
Alan Beban
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Cycling through the cells in a range

Just to add a little more explanation for the OP's benefit (not intended as
a criticism of Alan's suggested solution).
It could be as simple as the OP actually does not know how to loop through a
multicell contiguous range in which Alan's suggestion works well. I saw it
as a multicell discontiguous range in which Alan's solution would not work
(as written) but using "for each cell in selection" would work (in both
cases).

to illustrate:
Sub Tester9()
Debug.Print Selection.Address
For i = 1 To Selection.Count
Debug.Print i, Selection(i).Address
Next

End Sub

produces:
$F$22,$H$22,$F$31,$H$31
1 $F$22
2 $F$23
3 $F$24
4 $F$25

and using For each

Sub Tester10()
Debug.Print Selection.Address
i = 0
For Each cell In Selection
i = i + 1
Debug.Print i, cell.Address
Next
End Sub

produces:

$F$22,$H$22,$F$31,$H$31
1 $F$22
2 $H$22
3 $F$31
4 $H$31

just some additional information that may prove useful.

--
Regards,
Tom Ogilvy


"Alan Beban" wrote in message
...
Wandering mage wrote:

Can someone tell me how to cycle through the cells in a
range that has more than one cell selected?

For i = 1 To Selection.Count
MsgBox Selection(i).Address
Next
Alan Beban



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
Tab keeps cycling through the same row Mike Excel Discussion (Misc queries) 2 August 14th 08 12:20 AM
Cycling through workbooks Nico Excel Discussion (Misc queries) 4 July 4th 08 10:09 PM
Cycling though all sheets in the workbook James[_14_] Excel Programming 5 February 27th 04 04:11 PM
Cycling through worksheets Chris Gorham[_3_] Excel Programming 2 November 5th 03 08:37 PM
Need UDF help; cycling through various sheets using VBA name property Keith R[_3_] Excel Programming 3 July 23rd 03 02:06 PM


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