I used your tabs list in the Toc sheet to create a named dynamic range "Tabs" with this formula:
Formula:
=OFFSET(ToC!$C$6,,,COUNTA(ToC!$C$6:$C$1000),1)
Then I use that named range in the indirect countif:
Formula:
=SUMPRODUCT(COUNTIF(INDIRECT("'"&Tabs&"'!B3"),A4))
That formula is for the Race totals. In cell B4 and copied down.
The B3 in the INDIRECT function INDIRECT("'"&Tabs&"'!B3") must be manually changed for the other totals, like this for Ethnicity in B14 and copied down:
Formula:
=SUMPRODUCT(COUNTIF(INDIRECT("'"&Tabs&"'!B4"),A14))
I added a copy of Template tab named Template2 so I could test the formula.
As you add more tabs, they will populate your list and also added to the dynamic named range Tabs I created.
Please check file attached and let us know how it goes.
Good luck!
Bookmarks