Hello Everyone
Given the following source range on Worksheets(SOURCE):
And the following recipient table on Worksheets(RECIPIENT):
I would like to achieve this:
Where can I start? I wish my boss would give me enough time to suss this one out by myself, but unfortunately, he doesn't
Any help or pointers would be greatly appreciated!
Kind regards.
Given the following source range on Worksheets(SOURCE):
B738D ACCESS Lav Moc Overview- Input File_CEDRIC_TESTMACRO.xlsm | ||||
---|---|---|---|---|
A | B | |||
1 | Part Number | Function Code | ||
2 | PART NUMBER A | 1.01 | ||
3 | PART NUMBER B | 1.01 | ||
4 | PART NUMBER C | 1.02 | ||
5 | PART NUMBER D | 1.02 | ||
6 | PART NUMBER E | 1.02 | ||
7 | PART NUMBER F | 1.02 | ||
8 | PART NUMBER G | 1.02 | ||
9 | PART NUMBER H | 1.02 | ||
10 | PART NUMBER I | 1.02 | ||
11 | PART NUMBER J | 1.02 | ||
12 | PART NUMBER K | 1.04 | ||
13 | PART NUMBER L | 1.04 | ||
14 | PART NUMBER M | 1.04 | ||
15 | PART NUMBER N | 1.04 | ||
16 | PART NUMBER O | 1.05 | ||
17 | PART NUMBER P | 1.05 | ||
18 | PART NUMBER Q | 1.05 | ||
19 | PART NUMBER R | 1.05 | ||
20 | PART NUMBER S | 1.05 | ||
21 | PART NUMBER T | 1.05 | ||
22 | PART NUMBER U | 1.05 | ||
SOURCE |
And the following recipient table on Worksheets(RECIPIENT):
B738D ACCESS Lav Moc Overview- Input File_CEDRIC_TESTMACRO.xlsm | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Function Code | Part Number | Tests | ||
2 | 1.01 | Test1 | |||
3 | Test2 | ||||
4 | Test3 | ||||
5 | Test4 | ||||
6 | Test5 | ||||
7 | Test6 | ||||
8 | 1.02 | Test1 | |||
9 | Test2 | ||||
10 | Test3 | ||||
11 | Test4 | ||||
12 | Test5 | ||||
13 | Test6 | ||||
14 | 1.03 | Test1 | |||
15 | Test2 | ||||
16 | Test3 | ||||
17 | Test4 | ||||
18 | Test5 | ||||
19 | Test6 | ||||
20 | 1.04 | Test1 | |||
21 | Test2 | ||||
22 | Test3 | ||||
23 | Test4 | ||||
24 | Test5 | ||||
25 | Test6 | ||||
26 | 1.05 | Test1 | |||
27 | Test2 | ||||
28 | Test3 | ||||
29 | Test4 | ||||
30 | Test5 | ||||
31 | Test6 | ||||
RECIPIENT |
I would like to achieve this:
B738D ACCESS Lav Moc Overview- Input File_CEDRIC_TESTMACRO.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | Function Code | Part Number | Tests | |||
2 | 1.01 | PART NUMBER A | Test1 | 'VBA code looks at the Function Code in worksheets(RECIPIENT).Columns(A) then returns the matching range of Part Numbers from worksheets(SOURCE).Columns(A) in worksheets(RECIPIENT).Columns(B). 'If the matching range of Part Numbers for a particular Function Code is larger than 6 rows, then n rows need to be inserted to adjust for the difference: i.e. Function Code 1.02 has 8 matching Part Numbers - PART NUMBER C to PART NUMBER J - therefore we need to insert n = 8 - 6 = 2 extra rows before the next Function Code 1.03 to allow for PART NUMBER I and J. 'If the matching range Part Numbers for a particular Function Code is smaller than or equal to 6, then no need to insert new rows and the matching Part Numbers can just be copied in. 'If no matching Part Numbers are found for a particular Function Code, go to next Function Code. 'Worksheets(RECIPIENT).Columns(C) range Test1 to Test6 need to stay "anchored" at the top when inserted new rows. | ||
3 | PART NUMBER B | Test2 | ||||
4 | Test3 | |||||
5 | Test4 | |||||
6 | Test5 | |||||
7 | Test6 | |||||
8 | 1.02 | PART NUMBER C | Test1 | |||
9 | PART NUMBER D | Test2 | ||||
10 | PART NUMBER E | Test3 | ||||
11 | PART NUMBER F | Test4 | ||||
12 | PART NUMBER G | Test5 | ||||
13 | PART NUMBER H | Test6 | ||||
14 | PART NUMBER I | |||||
15 | PART NUMBER J | |||||
16 | 1.03 | Test1 | ||||
17 | Test2 | |||||
18 | Test3 | |||||
19 | Test4 | |||||
20 | Test5 | |||||
21 | Test6 | |||||
22 | 1.04 | PART NUMBER K | Test1 | |||
23 | PART NUMBER L | Test2 | ||||
24 | PART NUMBER M | Test3 | ||||
25 | PART NUMBER N | Test4 | ||||
26 | Test5 | |||||
27 | Test6 | |||||
28 | 1.05 | PART NUMBER O | Test1 | |||
29 | PART NUMBER P | Test2 | ||||
30 | PART NUMBER Q | Test3 | ||||
31 | PART NUMBER R | Test4 | ||||
32 | PART NUMBER S | Test5 | ||||
33 | PART NUMBER T | Test6 | ||||
34 | PART NUMBER U | |||||
RESULT |
Where can I start? I wish my boss would give me enough time to suss this one out by myself, but unfortunately, he doesn't
Any help or pointers would be greatly appreciated!
Kind regards.