Assuming your header row is in Row 1, use in A2

=IF(B2,ROW(A2)-1,"")

Format the cell & copy down