I believe you you'll be able to use the

THREED function if you download and install the free add-in

Morefunc.xll. Otherwise, if you don't particularly like Travis' second suggestion, I think you'd have to use something like the following formula...

=SUMPRODUCT(--(T(OFFSET(INDIRECT(A1:AE1&"!D1:D4000"),ROW(INDIRECT("1:4000"))-1,0,1))=$A3),--(N(OFFSET(INDIRECT(A1:AE1&"!T1:T4000"),ROW(INDIRECT("1:4000"))-1,0,1))=1),--(N(OFFSET(INDIRECT(A1:AE1&"!B1:B4000"),ROW(INDIRECT("1:4000"))-1,0,1))<>""),--(N(OFFSET(INDIRECT(A1:AE1&"!A1:A4000"),ROW(INDIRECT("1:4000"))-1,0,1))=1),--(N(OFFSET(INDIRECT(A1:AE1&"!U1:U4000"),ROW(INDIRECT("1:4000"))-1,0,1))<>""))

...where A1:AE1 contain numbers 1 through 31. I've assumed that Column D contains text values, and that other columns contain numerical values. If this is not correct, change the letters T and N accordingly. For example, if Column D contains numerical values instead, change the T to an N. Note that I've tested this formula using only three sheets, and found it somewhat slow. I imagine it'll be pretty slow with 31 sheets.

Hope this helps!