具体如下 图所示
我文件中有很多的sheet表,比如HW47 HW69 HW87等等,比如我想查找包含”中国人“内容的sheet表,而HW47 HW69里都有“中国人”,就在汇总表里显示HW47 HW69。谢谢各位大侠了,多给分。
不好意思,我还没说清楚,查找的内容不一定是 “中国人”,可能是其他,能否出来一个对话框,让我输入,或者我把查找的内容放sheet“汇总表”的B1单元格内,您看可否写代码。
追答Sub test()
Dim finstr As String
finstr = InputBox("请输入要查询的字符")
Dim sh As Worksheet
rw = 1 '从A1开始显示
For Each sh In Sheets
If sh.Name "汇总表" Then
If f1(sh, finstr) Then
Sheets("汇总表").Range("A" & rw) = sh.Name
rw = rw + 1
End If
End If
Next
End Sub
Function f1(sh As Worksheet, str1) As Boolean
On Error GoTo l_end
a = sh.Range("1:65536").Find(str1, LookIn:=xlValues, lookat:=xlPart)
f1 = True
Exit Function
l_end:
f1 = False
End Function
Sub 查找()
Dim i As Integer
Dim k As Integer
Dim x
Dim m As String
Dim s As Worksheet
Dim 汇总 As Worksheet
Set 汇总 = ThisWorkbook.Worksheets("汇总表")
k = 1
For i = 1 To ThisWorkbook.Sheets.Count
Set s = ThisWorkbook.Sheets(i)
If s.Name = "汇总表" Then
Else
For Each x In s.UsedRange
If x Like "*中国人*" Then
汇总.Cells(k, 1) = s.Name
k = k + 1
Exit For
End If
Next
End If
Next
MsgBox "查找完成"
End Sub
不好意思,我还没说清楚,查找的内容不一定是 “中国人”,可能是其他,能否出来一个对话框,让我输入,或者我把查找的内容放sheet“汇总表”的B1单元格内,您看可否写代码。
追答If x Like "*中国人*" Then
把中国人改成你需要查找的内容就行了。如果是要模糊查找的话,两边都加一个*