i have a COUNTIF function thats formula is as follows

=COUNTIF(Sheet3!AG:AG,A13)

however i want to condition it to exclude hidden cells once a filter is applied to column AG on sheet 3

i need some sort of mix between SUBTOTAL in which i can use 10X in order to exclude hidden cells but also be able to condition my search by counting all visible cells which matches the text in A13.

thanks in advance