gpt4 book ai didi

VBA找到找到的值的位置坐标

转载 作者:行者123 更新时间:2023-12-04 22:05:14 24 4
gpt4 key购买 nike

我有这个简单的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位置,即 Cells(x,y) Excel 中的值网格?

最佳答案

这是你想要的吗?

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

关于VBA找到找到的值的位置坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23764225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com