Reputation: 3914
I have a for each loop like this:
Dim rCell as range
Dim Searchrange as range
Set Searchrange = wss.Range("B12:B36") 'where wss is a defined worksheet
For Each rCell in SearchRange
'do some stuff
'get the row number of the worksheetrow rCell is currently refering to
Next rCell
How do I get the row number from the original worksheet (wss.
) that rCell
is currently holding the value of?
Upvotes: 1
Views: 10851
Reputation: 57753
There are 2 different "row numbers" I can imagine:
Searchrange
Example:
Dim SearchRange As Range
Set SearchRange = wss.Range("B12:B36") 'where wss is a defined worksheet
Dim rCell As Range
For Each rCell in SearchRange
'Absolute row number in the worksheet
Debug.Print rCell.Row 'returns 12, 13, 14, … 36
'Row number relative to the SearchRange
Debug.Print rCell.Row - Searchrange.Row + 1 'returns 1, 2, 3, … 25
Next rCell
Upvotes: 2