Excel VBA返回find的行

现在我有这个:

Range("B20:B60000").Select Selection.Find(What:=currentPerson, After:=ActiveCell, LookIn:= _ xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ xlNext, MatchCase:=False, SearchFormat:=False).Activate 

它select一定范围的单元格并findcurrentPerson(包含人名的variables)。 我如何做到这一点,以便我现在可以使用他的细胞作为参考,并获得他上面的行?

你可以使用下面的代码:

 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