To accomplish this with excel formulas, here's one way to do it.

Columns A and B contain your original data. Columns D and E are the original data in reverse order. Excel formulas generally work from the top down, instead of the bottom up. Reversing the original data makes it easier to use the formulas that follow. The formula for doing the reversing counts how many rows are left in the original data (ROWS(A2:$A$14)) and uses that as an index to the reversed value. So for D2 there are 13 rows (ROWS(A2:$A$14)), using INDEX that gets us A14. For D3 there are 12 rows (ROWS(A3:$A$14)), using INDEX that gets us A13...

Column F is where most of the work happens. The COUNTIFS is counting the number of rows that satisfy 2 conditions up to that point. The first condition is that the row must be equal to the category we're examining (so for F2 this would be D2 (33), for F8 this would be D8 (222)). The second condition is that the code is not equal to "ok". So for example the formula in F5 is counting the number of rows, between D2:D5 with a category of 33 and a code != "ok", the result is 1 (E3 is the only one).

To get the final counts we count the number of rows equal to the category we're counting, that have a count (Col F value) equal to zero.