现在我有这个:
Range("B20:B60000").Select
Selection.Find(What:=currentPerson, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
选择特定范围的单元格并查找currentPerson(包含人名的变量)。我如何制作它以便我现在可以使用他的细胞作为参考并获得他上方的行?
答案 0 :(得分:3)
您可以使用以下代码:
Dim res As Range
Set res = Range("B20:B60000").Find(What:=currentPerson, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If Not res Is Nothing Then
MsgBox "Address: " & res.Address
MsgBox "Row: " & res.Row
MsgBox "Cell above: " & Cells(res.Row - 1, res.Column).Address
MsgBox "Entire row above: " & Cells(res.Row - 1, res.Column).EntireRow.Address
Else
MsgBox "Nothing found"
End If