#### MixedUpExcel

##### Board Regular

- Joined
- Apr 7, 2015

- Messages
- 206

Hi,

Detail of data:

Column A has a list of product codes (of which there can be duplicates upto 5000 duplicates but in some cases, there may only be 1)

Column B has a list of associated product codes (there may also be duplicates as more than one of the products in Column A can be associated with the products in Column B) - I don't think the duplicate issue will come in to this though

I have a unique list of product codes from Column A and these are placed under a header in Column J

I have a number from 1 to 5000 as headers in Cell K1 going to the right ->>>

I want a VBA code which will take the product code from Cell J2 - find the corresponding code in Column A and return the product code next to it in Column B and put that code in Cell K2

As there will be duplicates, I want the code to then move to Cell L2 and look for the next instance in Column A where it finds the product code from Cell J2 (the second instance) and puts the result in Cell L2 and so on until it can't find any more products (Cell J2) in Column A

Then, it moves to Row 3, Column J and does the process again until it can't find any more of the Product Code (Cell J3) in Column A.

I will have potentially 40,000 Unique Codes in Column J

I have a formula which can do this but takes FAR TOO LONG to process.

This is my formula:

This is an example table as described above:

<colgroup><col span="2"><col><col span="7"><col><col span="5"></colgroup><tbody>

</tbody>

My thoughts were to possibly concatenate the unique codes in Column J with the header number (have an inserted Column at the start - a new Column A possibly) and using Countif eg. =Countif($A$2:A2,A2) in the new Column A - give me the number in the Count which I can concatenate in a new column and do a look up that way - or match / offset etc.

Is there any way to do the above or is there a better solution?

Thanks in advance.

Simon

Detail of data:

Column A has a list of product codes (of which there can be duplicates upto 5000 duplicates but in some cases, there may only be 1)

Column B has a list of associated product codes (there may also be duplicates as more than one of the products in Column A can be associated with the products in Column B) - I don't think the duplicate issue will come in to this though

I have a unique list of product codes from Column A and these are placed under a header in Column J

I have a number from 1 to 5000 as headers in Cell K1 going to the right ->>>

I want a VBA code which will take the product code from Cell J2 - find the corresponding code in Column A and return the product code next to it in Column B and put that code in Cell K2

As there will be duplicates, I want the code to then move to Cell L2 and look for the next instance in Column A where it finds the product code from Cell J2 (the second instance) and puts the result in Cell L2 and so on until it can't find any more products (Cell J2) in Column A

Then, it moves to Row 3, Column J and does the process again until it can't find any more of the Product Code (Cell J3) in Column A.

I will have potentially 40,000 Unique Codes in Column J

I have a formula which can do this but takes FAR TOO LONG to process.

This is my formula:

Code:

`{=INDEX(Sheet1!$B$2:$B$20000, SMALL(IF($J2=Sheet1!$A$2:$A$20000, ROW(Sheet1!$B$2:$B$20000)-MIN(ROW(Sheet1!$B$2:$B$20000))+1, ""), COLUMN(A1)))}`

This is an example table as described above:

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | |

1 | Product | Associated | Unique Product | 1 | 2 | 3 | 4 | 5 | |||||||

2 | AB123 | XY1 | AB123 | XY1 | XY4 | XY1 | XY4 | #NUM! | |||||||

3 | AB124 | XY2 | AB124 | XY2 | XY5 | XY2 | XY5 | #NUM! | |||||||

4 | AB125 | XY3 | AB125 | XY3 | XY6 | XY3 | XY6 | #NUM! | |||||||

5 | AB126 | XY4 | AB126 | XY4 | XY5 | XY1 | XY2 | XY4 | |||||||

6 | AB126 | XY5 | AB127 | XY6 | XY3 | XY6 | #NUM! | ||||||||

7 | AB127 | XY6 | AB128 | XY1 | XY4 | XY1 | #NUM! | ||||||||

8 | AB128 | XY1 | AB129 | XY2 | XY5 | XY2 | #NUM! | ||||||||

9 | AB129 | XY2 | AB130 | XY3 | XY6 | XY3 | #NUM! | ||||||||

10 | AB130 | XY3 | |||||||||||||

11 | AB123 | XY4 | |||||||||||||

12 | AB124 | XY5 | |||||||||||||

13 | AB125 | XY6 | |||||||||||||

14 | AB126 | XY1 | |||||||||||||

15 | AB126 | XY2 | |||||||||||||

16 | AB127 | XY3 | |||||||||||||

17 | AB128 | XY4 | |||||||||||||

18 | AB129 | XY5 | |||||||||||||

19 | AB130 | XY6 | |||||||||||||

20 | AB123 | XY1 | |||||||||||||

21 | AB124 | XY2 | |||||||||||||

22 | AB125 | XY3 | |||||||||||||

23 | AB126 | XY4 | |||||||||||||

24 | AB126 | XY5 | |||||||||||||

25 | AB127 | XY6 | |||||||||||||

26 | AB128 | XY1 | |||||||||||||

27 | AB129 | XY2 | |||||||||||||

28 | AB130 | XY3 | |||||||||||||

29 | AB123 | XY4 | |||||||||||||

30 | AB124 | XY5 | |||||||||||||

31 | AB125 | XY6 | |||||||||||||

32 | AB126 | XY1 |

<colgroup><col span="2"><col><col span="7"><col><col span="5"></colgroup><tbody>

</tbody>

My thoughts were to possibly concatenate the unique codes in Column J with the header number (have an inserted Column at the start - a new Column A possibly) and using Countif eg. =Countif($A$2:A2,A2) in the new Column A - give me the number in the Count which I can concatenate in a new column and do a look up that way - or match / offset etc.

Is there any way to do the above or is there a better solution?

Thanks in advance.

Simon

Last edited: