我有类似下面的代码,我想获取单元格的地址,如果找到值,则值为。因为如果宏在SomeRange中找到现有值,我想改变这个单元格的值。
Range(SomeRange).Select
Set a = Selection.Find(What:=Something, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
答案 0 :(得分:4)
你需要防止找不到任何东西。
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