ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Syntax - Loop through rows in a selection (https://www.excelbanter.com/excel-programming/398468-re-syntax-loop-through-rows-selection.html)

Dave Peterson

Syntax - Loop through rows in a selection
 
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


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com