用vba在多个工作表查找某个字符,怎么写代码?循环跟查找怎么合在一起用啊?
答案:3 悬赏:60 手机版
解决时间 2021-01-31 16:05
- 提问者网友:斑駁影
- 2021-01-30 19:40
用vba在多个工作表查找某个字符,怎么写代码?循环跟查找怎么合在一起用啊?比如说,在表1找不到我的字符,就到表2找,找不到再到表3找,求代码!!!
最佳答案
- 五星知识达人网友:不甚了了
- 2021-01-30 20:39
以下代码能满足你的要求,找到后激活此表并选中该单元格:
Sub 全工作簿查找字符串()
Dim Sh As Worksheet, Ra As Range
For Each Sh In Sheets
Set Ra = Sh.Cells.Find("需查找的字符串", , , 1)
If Not Ra Is Nothing Then
Sh.Activate
Ra.Select
Exit Sub
End If
Next
MsgBox "没有匹配的单元格!"
End Sub
Sub 全工作簿查找字符串()
Dim Sh As Worksheet, Ra As Range
For Each Sh In Sheets
Set Ra = Sh.Cells.Find("需查找的字符串", , , 1)
If Not Ra Is Nothing Then
Sh.Activate
Ra.Select
Exit Sub
End If
Next
MsgBox "没有匹配的单元格!"
End Sub
全部回答
- 1楼网友:佘樂
- 2021-01-30 22:55
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
- 2楼网友:山有枢
- 2021-01-30 21:25
找到名字是需要返回对应值,还是只是看看名字存不存在?
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯