I don't understand your Lot numbers - you appear to treat 2823 different than 2831, but 2831 the same as 2835. In any case, the attached should be easily modified, depending on how you really want to define unique Lots. I did it without scripting. I used a column of 1s which I then use a ColCumulSum function with accepts a By variable (which I use Lot for).