Replacement in the marks list

Hello Guys

please tell me I need to make a replacement in the list of marks, but taking into account the quantity

  1. I have 3 unsorted lists of lengths, corresponding brands to them and a list of the number of these lengths.
  2. the first time I just sort it in ascending order of length
  3. then I find the same lengths with different brands and the corresponding number of these marks
  4. I increase by the appropriate amount of lengths that have different marks
  5. then I rebuild the lists of stamps for the desired branches
  6. what is the problem, now I have stamps in the new list, lengths corresponding to the number, which have been replaced.
    now it is necessary to replace the marks in the corresponding lengths that were with different marks.

I have detailed the question in the file

if I wrote something that is not clear, please ask a clarifying question (28.5 KB)