LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Search an array of sheets for an array of numbers & return count of numbers

Range("A2:A10") is a list of numbers.

I want to search each sheet for each number in the list and return occurrence of each number to column B, next to the number.

As posted, code throws 'Subscript out of range' error on the line:
With nNumArr(i)

I had intended to also list the sheet names in column C and write that sheet list to the varSheets array, but have not got that far. Tried some similar things like the numbers list but that failed also, so I just wrote them in the array in the code as you see them.

The numbers list and the sheet list will be much larger in a working code.

Thanks,
Howard

Sub WSnNumCount()

Dim nNumArr() As Variant
Dim nNumCt As Long
Dim varSheets As Variant
Dim i As Long, ii As Long, j As Long
Dim c As Range

nNumArr = Range("A2:A10")

varSheets = Array("Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6")

For i = LBound(nNumArr) To UBound(nNumArr)

With nNumArr(i)

For ii = LBound(varSheets) To UBound(varSheets)

With Sheets(varSheets(ii))
Set c = .UsedRange.Find(What:=nNumArr(i), LookIn:=xlValues)

If Not c Is Nothing Then
j = j + 1
End If

End With

Next ' ii

End With

Range("B" & Rows.Count).End(xlUp)(2) = j

Next 'i
j = 0
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
count array for top three entries and return their number Rich DeVito Excel Discussion (Misc queries) 4 September 21st 09 02:29 AM
Which Function to Use? Search an Array, Return a Row Value [email protected] Excel Discussion (Misc queries) 1 August 24th 07 06:34 PM
Search array and return element No Ron Excel Worksheet Functions 7 May 17th 06 05:27 AM
average of kth largest numbers in an array of n numbers georgeb Excel Worksheet Functions 6 September 5th 05 05:57 AM
SEARCH EXCEL ARRAY FOR NON-VOIDS AND ENTER INTO ANOTHER ARRAY, ROSE THE RED Excel Programming 1 December 31st 04 06:01 PM


All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"