Vba 获取函数中单元格的地址。查找
我有下面这样的代码,我想得到单元格的地址,其中的值是,若找到值。因为若宏在某个范围内找到现有值,我想更改此单元格的值Vba 获取函数中单元格的地址。查找,vba,excel,Vba,Excel,我有下面这样的代码,我想得到单元格的地址,其中的值是,若找到值。因为若宏在某个范围内找到现有值,我想更改此单元格的值 Range(SomeRange).Select Set a = Selection.Find(What:=Something, After:=ActiveCell, LookIn:=xlValues, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase
Range(SomeRange).Select
Set a = Selection.Find(What:=Something, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
你需要防止找不到任何东西
dim a as range
Range(SomeRange).Select
on error resume next
Set a = Selection.Find(What:=Something, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
if not a is nothing then
debug.print a.address(0, 0)
a = "changed value"
end if
你需要防止找不到任何东西
dim a as range
Range(SomeRange).Select
on error resume next
Set a = Selection.Find(What:=Something, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
if not a is nothing then
debug.print a.address(0, 0)
a = "changed value"
end if
MsgBox a.address
除非我遗漏了什么。MsgBox a.address
除非我遗漏了什么。可以立即跳过选择
。是的,但是如果没有定义父工作表,我会感到内疚。通过使用OP的代码,我可以将其留给OP,以确保引用了正确的工作表。.Find
不需要关闭错误处理,如果找不到提供的值,它将不返回任何内容。@lturner-感谢您捕捉到这一点。这也给了我重新访问并修复end-fi
@user3819867的借口-我相信这取决于VBE的工具是什么► 选择权► 一般的► 错误捕获设置为。但是你是对的,它应该可以捕捉所有场景。可以立即跳过选择
。是的,但是如果没有定义父工作表,我会感到内疚。通过使用OP的代码,我可以将其留给OP,以确保引用了正确的工作表。.Find
不需要关闭错误处理,如果找不到提供的值,它将不返回任何内容。@lturner-感谢您捕捉到这一点。这也给了我重新访问并修复end-fi
@user3819867的借口-我相信这取决于VBE的工具是什么► 选择权► 一般的► 错误捕获设置为。但你是对的,它应该在那里捕捉所有场景。