Multi conditional Count across multiple sheets

Sandeep Warrier

Well-known Member
Joined
Oct 31, 2008
Messages
2,680
Hey All,

Looking for a way to do a multi-conditional countif across multiple sheets.

I know the THREED function works, but trying to increase my UDF knowledge.

The UDF below seems to work. Any suggestions/improvements would be appreciated.

Also, is there a way to increase the Conditions part? The current UDF takes only 2 conditions.

I know there is PARAMARRAY, but I'm not sure how to use it in this case.

Excel Workbook
AB
3ABCDGHI
4EFGHJKL
5ABCDJKL
6EFGHGHI
7ABCDGHI
8EFGHGHI
9ABCDGHI
10EFGHJKL
Sheet1
Excel Workbook
AB
3ABCDGHI
4EFGHJKL
5ABCDJKL
6EFGHGHI
7ABCDGHI
8EFGHGHI
9ABCDJKL
10EFGHJKL
Excel 2003 Sheet2
Excel Workbook
AB
3ABCDGHI
4EFGHJKL
5ABCDJKL
6EFGHGHI
7ABCDGHI
8EFGHGHI
9ABCDJKL
10EFGHJKL
Excel 2003 Sheet3
Excel Workbook
ABCDEF
2UDFTHREEDSheet Names
3ABCDGHI77Sheet1
4ABCDJKL55Sheet2
5EFGHGHI66Sheet3
6EFGHJKL66
Excel 2003 Sheet4
Excel 2003
Cell Formulas
RangeFormula
C3=Count3DMulSheet($A$3:$A$10,A3,$B$3:$B$10,B3,$F$3:$F$5)
C4=Count3DMulSheet($A$3:$A$10,A4,$B$3:$B$10,B4,$F$3:$F$5)
C5=Count3DMulSheet($A$3:$A$10,A5,$B$3:$B$10,B5,$F$3:$F$5)
C6=Count3DMulSheet($A$3:$A$10,A6,$B$3:$B$10,B6,$F$3:$F$5)
D3=SUMPRODUCT(--(THREED(First:Last!$A$3:$A$10)=A3),--(THREED(First:Last!$B$3:$B$10)=B3))
D4=SUMPRODUCT(--(THREED(First:Last!$A$3:$A$10)=A4),--(THREED(First:Last!$B$3:$B$10)=B4))
D5=SUMPRODUCT(--(THREED(First:Last!$A$3:$A$10)=A5),--(THREED(First:Last!$B$3:$B$10)=B5))
D6=SUMPRODUCT(--(THREED(First:Last!$A$3:$A$10)=A6),--(THREED(First:Last!$B$3:$B$10)=B6))



Code:

Code:
Function Count3DMulSheet(rngCond1 As Range, Cond1 As Variant, rngCond2 As Range, Cond2 As Variant, ShtRng As Range) As Double

    Dim arr1 As Variant
    Dim arr2 As Variant
    Dim arr3 As Variant
    Dim WF As WorksheetFunction
    
    Set WF = Application.WorksheetFunction
    
    arr1 = WF.Transpose(ShtRng)
        
    Count3DMulSheet = 0
    
    For Each arr In arr1
    
        arr2 = WF.Transpose(Sheets(arr).Range(rngCond1.Address))
        For I = 1 To UBound(arr2)
        
            If arr2(I) = Cond1 Then
                arr2(I) = 1
            Else
                arr2(I) = 0
            End If
        
        Next
        
        arr3 = WF.Transpose(Sheets(arr).Range(rngCond2.Address))
        For I = 1 To UBound(arr3)
        
            If arr3(I) = Cond2 Then
                arr3(I) = 1
            Else
                arr3(I) = 0
            End If
        
        Next
        
        Count3DMulSheet = Count3DMulSheet + WF.SumProduct(arr2, arr3)
    
    Next

End Function
<input id="gwProxy" type="hidden"><!--Session data--><input *******="jsCall();" id="jsProxy" type="hidden"><input id="gwProxy" type="hidden"><!--Session data--><input *******="jsCall();" id="jsProxy" type="hidden">
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,927
Messages
6,175,437
Members
452,641
Latest member
Arcaila

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top