Vba 如何获取for each循环中单元格的行号

Vba 如何获取for each循环中单元格的行号,vba,excel,Vba,Excel,我对每个循环都有一个类似的: 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 referi

我对每个循环都有一个类似的:

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
如何从原始工作表(
wss.
)中获取当前保存值为的
rCell
的行号?

我可以想象有两种不同的“行号”:

  • 工作表中的绝对行数
  • 相对于
    搜索范围的行号
  • 例如:

    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
    

    debug.print rcell.row
    也许..?关于
    rcell.row
    呢@你比我快了半秒。有时候最难的事情有最简单的解决办法。几个小时来我一直在想这个问题-\它将返回一个介于12和36之间的数字,具体取决于您所处的循环迭代。而
    rCell.Row
    返回绝对行号
    rCell.Row-Searchrange。Row+1
    将返回相对于
    Searchrange
    的行号。