如何searchExcel的每个工作表中的特定列

我有一个超过50个工作表的excel文档,都有一个类似的命名约定。 由于这对于用户来说是非常不友好的,所以我写了一个VBAmacros,它创build了一个名为summary的工作表,其中所有工作表的列表都以表格forms超链接,以表格AB和C作为列和表格1和2作为行。

现在我正在尝试通过表1和表2中特定列的每一行,并查找对SheetB,SheetC和SheetD的任何引用,并且find每个引用,并且要标记创buildmatrix。

我不知道如何做到这一点。 任何援助将不胜感激。

我设法searchSheet 1和2以获取SheetB的任何引用,但是我不知道如何更新汇总表中的相应单元格。

Function findWord(word As String, wSheet As String) As Boolean Dim LastRow As Long Dim i As Long LastRow = Worksheets(wSheet).Cells(Rows.Count, "D").End(xlUp).Row For i = LastRow To 1 Step -1 If Worksheets(wSheet).Range("D" & i).Value = word Then findWord = True Exit Function End If Next i End Function For Each wsSheet In wbBook.Worksheets If (wsSheet.Name <> wsActive.Name) And (Left(wsSheet.Name, 4) <> "fact") Then For i = 2 To lastColumn MsgBox wsSheet.Name If findWord(columnNames(counter2), wsSheet.Name) Then 'Update summary sheet End If counter = counter2 + 1 Next i End If Next wsSheet 

如果您正在查找的“汇总表”中的结果与此类似:
汇总表上的表格

那么你可以使用这样的东西(阅读代码中的注释解释)

 Sub MarkReferencesToSheets() Dim wsSummary As Worksheet 'sheet with summary table matrix Dim wsSheetRow As Worksheet 'sheets in which we will search references to other sheets Dim strSheetColumnName As String 'name of the reference we are looking for Dim intSheetRow As Integer 'for loop purposes Dim intSheetColumn As Integer 'for loop purposes Set wsSummary = Sheets("Summary") For intSheetRow = 2 To 3 'change to suit; headers for rows in summary sheet Set wsSheetRow = Worksheets(wsSummary.Cells(intSheetRow, 1).Value) For intSheetColumn = 2 To 4 'change to suit; headers for columns in summary sheet strSheetColumnName = wsSummary.Cells(1, intSheetColumn) 'name of sheet we are looking for If Not wsSheetRow.Columns(4).Find(strSheetColumnName) Is Nothing Then 'look only in column "D", or 4 wsSummary.Cells(intSheetRow, intSheetColumn) = "X" ' if we found it, mark it Else 'if you want something else in the cell when reference is not found, put it here End If Next intSheetColumn Next intSheetRow End Sub