作者:行者05965 | 来源:互联网 | 2023-05-25 10:37
在Excel VBA中查找方法以查找列"C"包含已知值的最后一个行号.
1> Gary's Stude..:
这将在C列中找到最后一次幸福
Sub SeekHappiness()
Dim C As Range, where As Range, whatt As String
whatt = "happiness"
Set C = Range("C:C")
Set where = C.Find(what:=whatt, after:=C(1), searchdirection:=xlPrevious)
MsgBox where.Address(0, 0)
End Sub
要仅输出行号,请使用:
MsgBox Mid(where.Address(0, 0), 2)
要找到第一个匹配项:
Sub SeekHappiness()
Dim C As Range, where As Range, whatt As String
whatt = "happiness"
Set C = Range("C:C")
Set where = C.Find(what:=whatt, after:=C(1))
MsgBox where.Address(0, 0)
End Sub