This formulas assumes 1000 rows or less per subtotal.

Plop this into B8 and copy down as far as needed.

=IF(AND(NOT(ISBLANK(A9)),ISNUMBER(C8)),INDEX(A8:A1000,MATCH("C"&"*",A8:A1000,0)),"")

Feel free to adjust the range to less rows.

Do not use absolute references (meaning that when the formula is copied down 30 rows, the formula in B29 will roll to:

=IF(AND(NOT(ISBLANK(A30)),ISNUMBER(C29)),INDEX(A29:A1021,MATCH("C"&"*",A29:A1021,0)),"")