下面是我用的宏录出来的代码,在A列,查找变量A,找到了,继续向下执行代码,
没找到,直接用GOTO 10。
现在的问题是,如果找不到变量A,程序会出错。
Range("A:A").Select
Selection.Find(What:=A, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, MatchByte:=False, SearchFormat:=False).Activate
我还不太想用循环语句一个单元格一个单元格的找。
VBA 查找问题
答案:2 悬赏:0
解决时间 2021-01-03 23:26
- 提问者网友:白越
- 2021-01-03 14:00
最佳答案
- 二级知识专家网友:眠于流年
- 2021-01-03 14:34
定义一个单元格变量,如:Ra
set Ra=Range("A:A).Find(What:=A, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, MatchByte:=False, SearchFormat:=False)
if ra is nothing then goto 10'如果没有找到
'继续执行的代码
set Ra=Range("A:A).Find(What:=A, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, MatchByte:=False, SearchFormat:=False)
if ra is nothing then goto 10'如果没有找到
'继续执行的代码
全部回答
- 1楼网友:开心就好
- 2021-01-03 14:45
sub macro1()
dim xrng as range, firstrng as range
if left(range("a1"), 3) = "d1[" then
set firstrng = range("a1")
else
set firstrng = cells.find("d1[")
end if
set xrng = cells.find("d1[", firstrng)
if xrng is nothing then
msgbox "没有了"
else
msgbox xrng.row
end if
end sub
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯