Count if across tabs

MartinL

Well-known Member
Joined
Oct 16, 2008
Messages
1,141
Office Version
  1. 365
Platform
  1. Windows
I have a workbook with 52 tabs all identical in layout
Example
I am trying to create a formula that will look at cell D2 in each tab (except the one i am in) and count if the cell = 'x'
is it is easy to do this or do I need to create a megaformula
 
Last edited:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If the choice is between an "x" or nothing, then you can use a fairly simple 3-D formula, like in B3 shown here. Make sure that there are no sheets between the start and end sheet that you don't want included.

If there could be something else in D2, then you could use a formula like in C5 here. Put the list of sheets you want to include in B5:B6 (or whatever).


Excel 2012
BCD
2x
32
4
5Sheet62
6Sheet7

<tbody>
</tbody>
Sheet6

Worksheet Formulas
CellFormula
B3=COUNTA(Sheet6:Sheet7!D2)
C5=SUMPRODUCT(COUNTIF(INDIRECT("'"&B5:B6&"'!D2"),"x"))

<tbody>
</tbody>

<tbody>
</tbody>
 
Last edited:
Upvote 0
try this function:
Code:
Function CountIfSheets(SearchRange As Range, LookFor As Variant, Optional ExcludeThisSheet As Boolean = True)
    Dim wsh As Worksheet
    Dim rng As String: rng = SearchRange.Address
    Dim wnm As String: wnm = Application.Caller.Parent.Name
    
    CountIfSheets = 0
    
    For Each wsh In ThisWorkbook.Worksheets
        If ExcludeThisSheet Then
            If wsh.Name <> wnm Then
                If wsh.Range(rng).Value = LookFor Then CountIfSheets = CountIfSheets + 1
            End If
        Else
            If wsh.Range(rng).Value = LookFor Then CountIfSheets = CountIfSheets + 1
        End If
    Next wsh
    
    Set wsh = Nothing
    
End Function
 
Upvote 0
If the choice is between an "x" or nothing, then you can use a fairly simple 3-D formula, like in B3 shown here. Make sure that there are no sheets between the start and end sheet that you don't want included.

Hi Eric W

Your solution =COUNTA(Sheet2:Sheet62!D2) looked as if it was exactly what I needed however Excel refused to accept it as a formula my worksheet was Sheet1 so there were no sheets in between. However the sheets had been renamed, so by looking at the VBA screen I found that the sheets were in order 2 to 62

But thanks for your help.

Martin
 
Last edited:
Upvote 0
Hi Bobsan42

I was hoping to avoid VBA - people here don't like it much, but the function was actual good and worked first time so we have gotten away with it.

Thank you very much.

Martin
 
Upvote 0
It may be that Excel didn't take the formula if you renamed the Sheets with spaces in them. In such a case, you'd need to put quotes around the sheet names like so:

=COUNTA('Jan 2019:Mar 2019'!D2)

Some people like to create a couple of "dummy" sheets named Start and Finish. Then put those around the other sheets you want to check and use

=COUNTA(Start:Finish!D2)

If you ever add sheets to your range, just drag the Finish sheet tab to include the new sheets.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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