如果我知道单元数据和我期望数据所在的列号。请让我知道如何检索该单元格的行号。 谢谢。
答案 0 :(得分:4)
使用Excel Application object使用MATCH function。
Vob_I
答案 1 :(得分:4)
以下是 B 列的一种方法:
Sub HappinessRow()
Dim r As Range
Set r = Range("B:B").Find(what:="happiness", after:=Range("B1"))
If r Is Nothing Then
MsgBox "could not find happiness"
Exit Sub
End If
MsgBox "happiness found in row " & r.Row
End Sub
修改#1:强>
此版本使用要查找的值的参数和要搜索的列:
Sub HappinessRow2()
Dim r As Range, s As String, kolumn As Long
s = "happiness"
kolumn = 2
Set r = Cells(1, kolumn).EntireColumn.Find(what:="happiness", after:=Cells(1, kolumn))
If r Is Nothing Then
MsgBox "could not find happiness"
Exit Sub
End If
MsgBox "happiness found in row " & r.Row
End Sub