为了一顿小龙虾,不惜花了一下午时间。
Sub 小龙虾()
Dim sheetCnt As Integer, zongbiaorow As Integer, biaorow As Integer, i As Integer, j As Integer, k As Integer, p As Integer
Dim s As String, target As String
Dim ww As Range
sheetname = ActiveWindow.ActiveSheet.Name '当前表格名字
sheetCnt = Worksheets.Count '表示数量
zongbiaorow = ActiveSheet.UsedRange.Rows.Count '总表行数
Debug.Print "总表行数", zongbiaorow
For j = 1 To zongbiaorow
target = Cells(j, 3).Value '要查找的对象
'遍历表格
For i = 1 To sheetCnt
If Worksheets(i).Name <> sheetname Then '排除总表
Set ww = Application.ThisWorkbook.Worksheets(i).Range("C:C").Find(target, , , , , , xlNext)
If Not ww Is Nothing Then
Debug.Print "查找数据", target, " 在", Worksheets(i).Name, " 在", ww.Row
Application.ThisWorkbook.Worksheets(i).cells(j,9) = Worksheets(i).Name
End If
End If
Next
Next
MsgBox "吃小龙虾了"
End Sub