在函数中获取单元格的地址

问题描述 投票:1回答:1

我有类似下面的代码,我想获取单元格的地址,如果找到值,则值为。因为如果宏在SomeRange中找到现有值,我想改变这个单元格的值。

Range(SomeRange).Select
    Set a = Selection.Find(What:=Something, After:=ActiveCell, LookIn:=xlValues, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)
excel vba excel-vba
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.