Tuesday, 17 September 2013

Sum of Sumif Over Multiple Sheets

Sum of Sumif Over Multiple Sheets

I know Im not doing this properly but I am a VBA beginner and am trying to
perform a sumif of a value on multiple sheets in a workbook and then
return a sum of those sumifs.
This is how I tried but I get a #NAME? error and don't know where to go
from here.
Public Function Lookup(x As Long) As Long
Dim sh As Worksheet, wb As Workbook, arr() As Variant
Set wb = Workbooks.Open("Purchased.xlsm")
For Each sh In wb
arr() = Application.SumIf(Range("A1:A10000"), x, Range("B1:B10000"))
Next
Lookup = Application.WorksheetFunction.Sum(arr())
End Function

No comments:

Post a Comment