vba 如何从Excel VBA中的查找功能获取单元格地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41008736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get cell address from Find function in Excel VBA
提问by Randy Adhitama
How do I get cell address using Find function.
如何使用 Find 功能获取单元格地址。
Here's the code
这是代码
Dim Found As Range
Set Found = Worksheets("Sheet 1").Cells.Find(What:="test", LookAt:=xlWhole, MatchCase:=True)
If Not Found Is Nothing Then
' do something
End If
When I debug the code, "Found" variable contain a "string" instead of cell address.
当我调试代码时,“Found”变量包含一个“字符串”而不是单元格地址。
回答by nightcrawler23
It seems you can just use found.addresseven though it shows as string. The below code worked for me.
found.address即使它显示为字符串,您似乎也可以使用。下面的代码对我有用。
Sub findCellAddress()
Dim ra As Range
Set ra = Cells.Find(What:="fff", LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If ra Is Nothing Then
MsgBox ("Not found")
Else
MsgBox (ra.Address)
End If
End Sub
回答by James Greaves
I could not find this anywhere ON THE Internet. This code will give you the Row AND Column.
我在互联网上的任何地方都找不到这个。此代码将为您提供行和列。
Dim ThisPos As Range
With Range("A1:J100")
Set ThisPos = .Find(What:="List_Position", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not ThisPos Is Nothing Then
Cell_Add= Split(ThisPos.Address, "$")
ThisRow = Cell_Add(1)
ThisCol = Cell_Add(2)
End If
End With

