In short:
I have 3 columns. Column A is Sheet Name, Column B is Individual's Name, Column 3 is number of instances.
I want to count the number of instances the person's name from column B occurs in a dynamic list of worksheets in column A.
More details:
I have a workbook with many worksheets. Some of worksheets begin with the name "Test". I want to search each worksheet that begin with "Test" and find how many times a name (from column B) occurs.
I have two parts to this.
- A macro lists all of the worksheets that begin with "Test" and puts them in column A.
- A formula in column C goes into each sheet in column A and finds the number of instances the name in Column B occurs.
The issue is new tabs that begin with "Test" can be added.
How do I make the formula dynamic and search for all of column A?
Sub WorksheetLoop()
Dim WS_Count As Integer
Dim I As Integer
Dim R As Integer
' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = ActiveWorkbook.Worksheets.Count
R = 2
' Begin the loop.
For I = 1 To WS_Count
If (InStr(1, ThisWorkbook.Worksheets(I).Name, "Test")) > 0 Then
ThisWorkbook.Worksheets("Master").Cells(R, 1) = ActiveWorkbook.Worksheets(I).Name
R = R + 1
End If
Next I
End Sub
Formula:
=SUMPRODUCT(COUNTIF(INDIRECT("'"&$A$2:$A5&"'!A1:EE2000"),B2))