OK, I'm not very good at putting spreadsheets into words, but here goes:
D1= The number of consecutive free codes you need (entered by user)
D5 and downwards = 'XXX' to show which codes are being taken. Blank = free.
C5 and downwards = consecutively numbered product codes.
A5 and downwards = IF(D5<>"",0,A4+1).
D2 = First free product number available =(VLOOKUP($D$1,A:C,3,FALSE)-D1+1)
Its not pretty, but it seems to work