我有这个简单的macro
,它会转到值所在的位置。
Sub dkdk()
Dim dk As String
Dim rng
dk = "Document Type"
If Trim(dk) <> "" Then
With Sheets(1).Range("1:10")
Set rng = .Find(dk, .Cells(.Cells.Count), xlValues, xlWhole, xlByRows, xlNext, _
False)
Application.Goto rng, True
If Then
End If
End With
End If
End Sub
如何在[{1}}网格中接收msgbox
位置即Cells(x,y)
的位置?
答案 0 :(得分:2)
这是你想要的吗?
Sub dkdk()
Dim dk As String
Dim rng As Range
dk = "Document Type"
If Trim(dk) <> "" Then
With Sheets(1).Range("1:10")
Set rng = .Find(dk, .Cells(.Cells.Count), xlValues, xlWhole, _
xlByRows, xlNext, False)
If Not rng Is Nothing Then
Application.Goto rng, True
'<~~ This will give something like $A$1
MsgBox rng.Address
'<~~ This will give something like Cells(1,1)
MsgBox "Cells(" & rng.Row & "," & rng.Column & ")"
End If
End With
End If
End Sub
答案 1 :(得分:1)
,插入以下内容:
msgbox "rownumber: " & rng.row & ", columnnumber: " & rng.column
并且,如果您想错误检查:
if not rng is nothing then
msgbox "rownumber: " & rng.row & ", columnnumber: " & rng.column
end if