VBAfindfind的值的位置坐标

我有这个简单的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 

我怎样才能在一个msgbox的位置,即Excel网格中的值的Cells(x,y)

这是你想要的吗?

 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 

在Application.Goto语句之前插入以下内容:

 msgbox "rownumber: " & rng.row & ", columnnumber: " & rng.column 

如果你想错误检查:

 if not rng is nothing then msgbox "rownumber: " & rng.row & ", columnnumber: " & rng.column end if