VBA Excel如何在工作表区域内查找某个值,发回这个值所在的行号、列号

2024-10-28 21:50:22
推荐回答(2个)
回答1:

Sub 查找()
For Each rng In Range("a1:d3")
    If rng = 7 Then
        a = rng.Row
        b = rng.Column
    End If
Next
MsgBox "行号为" & a & "-" & "列号为" & b
End Sub

回答2:

Sub aa()
Dim a As Range
For Each a In Range("A1:D3")
If a.Value = 7 Then
MsgBox "a=" & a.Row & " , b=" & a.Column
End If
Next
End Sub