Search an array of sheets for an array of numbers & return countof numbers
Hi Claus and Garry,
Here is what I am using which seems to work well.
I think I was unclear about the sheet names in column C. I meant that I wanted to list the sheets that were in the workbook that I wanted to search in for the numbers.
I used the example you both pointed out about being 2D and the code now takes a list of sheest in column C and they are the "search in" sheets.
I commented out the line that listed the sheets where the numbers were found.
And just for the record I had just found this as an example and failed to recognize it was what I was dealing with. Sorry.
*****
For a zero-based two dimensional array...
Code:
First row, second column:
arr(0,1)
*****
Thanks to both of you.
Howard
Sub WSnNumCount()
Dim nNumArr As Variant
Dim nNumCt As Long
Dim varSheets As Variant
Dim i As Long, ii As Long
Dim c As Range
Dim FirstAddress As String
nNumArr = Sheets("Sheet1").Range("A2:A10")
varSheets = Sheets("Sheet1").Range("C2:C6")
For i = LBound(nNumArr) To UBound(nNumArr)
For ii = LBound(varSheets) To UBound(varSheets)
With Sheets(varSheets(ii, 1))
Set c = .UsedRange.Find(What:=nNumArr(i, 1), LookIn:=xlValues, _
lookat:=xlWhole)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
Sheets("Sheet1").Cells(i + 1, 2) = Sheets("Sheet1").Cells(i + 1, 2) + 1
'Sheets("Sheet1").Cells(i + 1, 3) = Sheets("Sheet1").Cells(i + 1, 3) & Chr(10) & _
Sheets(varSheets(ii)).Name & "!" & c.Address(0, 0)
Set c = .UsedRange.FindNext(c)
Loop While Not c Is Nothing And c.Address < FirstAddress
End If
End With
Next ' ii
Next 'i
End Sub
|