如何在以下代码中获取在其中找到值的范围或行号? 在“如果”部分中,我想要行号,而不是转到这段代码中的值
With wsSource.Range("A:A") 'searches all of column A
Set Rng1 = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng1 Is Nothing Then
Application.Goto Rng1, True 'value found
Else
MsgBox "Nothing found" 'value not found
End If
End With
答案 0 :(得分:0)
激活Rng1
,然后获得如下所示的活动单元格行。
With wsSource.Range("A:A") 'searches all of column A
Set Rng1 = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng1 Is Nothing Then
'Your code
Rng1.Activate
'Get Row number
MsgBox ActiveCell.Row
'Get Row value
MsgBox ActiveCell.Value
Else
MsgBox "Nothing found" 'value not found
End If
End With