Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Syntax - Loop through rows in a selection

I want to modify the following code that loop through each item in a selection
-----
Dim x as Range

For Each x In Selection
retrievename = Sheets("EmailList").Range("B" & x.Row).value
Next x
------

I want it to only loop through each row in the selection (not each item)

What is the proper syntax

I thought Maybe this would work ... but I was wrong. It loops the proper
number of times however SelectRow always refers to the first row that is
selected
--------
For counter = 1 To Selection.Rows.Count
SelectRow = Selection.row
retrievename = Sheets("EmailList").Range("B" & SelectRow).value
Next counter
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Syntax - Loop through rows in a selection

For Each x in Selection.Rows

That worked - Thanks

Perfect!

"Dave Peterson" wrote:

Maybe...

Dim x as Range
For Each x In Selection.Rows
retrievename = Sheets("EmailList").Range("B" & x.Row).value
Next x

Or

Dim iRow as long
for irow = selection.row to selection.rows.count + selection.row -1
retrievename = sheets("emaillist").range("B" & irow).value
'or
retrievename = sheets("emaillist").cells(irow,"B").value
next irow



Lisab wrote:

I want to modify the following code that loop through each item in a selection
-----
Dim x as Range

For Each x In Selection
retrievename = Sheets("EmailList").Range("B" & x.Row).value
Next x
------

I want it to only loop through each row in the selection (not each item)

What is the proper syntax

I thought Maybe this would work ... but I was wrong. It loops the proper
number of times however SelectRow always refers to the first row that is
selected
--------
For counter = 1 To Selection.Rows.Count
SelectRow = Selection.row
retrievename = Sheets("EmailList").Range("B" & SelectRow).value
Next counter


--

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
Syntax for stopping a Do Loop? bondjel Excel Discussion (Misc queries) 5 March 22nd 10 01:35 PM
Syntax - Loop through rows in a selection Dave Peterson Excel Programming 0 October 1st 07 08:07 PM
Do...Loop syntax help? DB74 Excel Programming 5 September 4th 07 07:04 PM
What is the selection syntax hon123456 Excel Programming 6 September 12th 06 02:20 AM
loop syntax Knox Excel Programming 2 May 17th 06 06:57 PM


All times are GMT +1. The time now is 10:50 AM.

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"