如何从excelvba中的Find函数中获取单元格地址
如何使用Find函数获取单元格地址 这是密码如何从excelvba中的Find函数中获取单元格地址,excel,vba,find,Excel,Vba,Find,如何使用Find函数获取单元格地址 这是密码 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 当我调试代码时,“Found”变量包含一个“string”而不是单元格地址。看起来您可以直接使用Found.add
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
当我调试代码时,“Found”变量包含一个“string”而不是单元格地址。看起来您可以直接使用
Found.address
,即使它显示为string。下面的代码适用于我
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
Dim SValue As Range
With Range("D1:D100")
Set SValue = .Find(What:="Searched Value", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not SValue Is Nothing Then
Cell_Split_R = Split(SValue.Address(ReferenceStyle:=xlR1C1), "R")
Cell_Split_C = Split(Cell_Split_R(1), "C")
SCol = Cell_Split_C(0)
SRow = Cell_Split_C(1)
End If
End With
我在网上找不到这个。 此代码将为您提供行和列
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
此代码将为您提供单元格地址的引用样式
Dim SValue As Range
With Range("D1:D100")
Set SValue = .Find(What:="Searched Value", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not SValue Is Nothing Then
Cell_Split_R = Split(SValue.Address(ReferenceStyle:=xlR1C1), "R")
Cell_Split_C = Split(Cell_Split_R(1), "C")
SCol = Cell_Split_C(0)
SRow = Cell_Split_C(1)
End If
End With
Find
可以返回Nothing
,因此将.Address
固定在它的末尾是非常困难的<代码>查找应始终设置为临时的范围
对象,并在使用任何属性之前对其进行测试。您好@nightcrawler23感谢您的反馈。有没有办法分别从“ra.Address”中获取行和列?我想将其应用于单元格选择(例如:cells(1,2)),一个范围具有行和列属性。因此可以使用ra.Row和ra.Column来获取值@RandyAdhitama当您在ra
之后键入
点时,应该会有一个小的就地下拉列表(即IntelliSense)显示所有可用的成员。探索一下。当你不确定他们在做什么时,在网上调查他们——所有事情都有完整的记录。您还可以使用对象浏览器(VBE编辑器中的F2)浏览所有引用库中的所有类型和成员。找到的
变量不包含字符串
,您已将其声明为范围
,因此它包含范围
对象引用。-使用它。您看到的字符串内容是范围的值
,这是默认属性(即未指定成员时隐式引用的成员)。此答案很有用,但可能需要一些工作。您可以放入变量类型声明,但我相信ThisRow实际上得到了列,ThisColumn得到了行。