I have a tricky VBA question concerning Arrays (or possibly Collections): I would like to use two values located on the same row from Array1 (Sheet1) to search for the first instance of those same two values on the same row found in Array2 (Sheet2).
1) find the first instance of two values on the same row (Apple + Pie, Kiwi + Tart, Apple + Tart and Peach + Pie) from Array1 within Array2 on Sheet2
2) copy a value in a cell adjacent to that match from Sheet2 to Sheet1
3) delete the entire row on Sheet2 that contained the match to prevent repeats
4) continue the search using the values found in Array1 on Sheet1
I have a workbook with two sheets.
Sheet1 contains an array populated with data from Columns A & B:
Sheet2 also contains an array populated with data from Columns A & B:
For example, the Macro would look for the first row which contains the terms Apple and Pie. It copy the value from Column E from Sheet2 over to the corresponding row in Sheet1, Column C. Finally it would delete the matched row from Sheet2 and continue searching for the remaining values in Array1 (Apple + Pie, Kiwi + Tart, Apple + Tart and Peach + Pie).
After running the macro, Sheet1 should appear as follows:
And Sheet2 would appear as follows since all but Cherry | Pie | Zebra were found and their rows were deleted:
***
I'm not sure how to determine what row an array element resides. For example a search for Peach + Pie in array2 might tell me that both terms exists on the same row but how can I tell that both values are located on Row 6?
Any suggestions would be greatly appreciated!
1) find the first instance of two values on the same row (Apple + Pie, Kiwi + Tart, Apple + Tart and Peach + Pie) from Array1 within Array2 on Sheet2
2) copy a value in a cell adjacent to that match from Sheet2 to Sheet1
3) delete the entire row on Sheet2 that contained the match to prevent repeats
4) continue the search using the values found in Array1 on Sheet1
I have a workbook with two sheets.
Sheet1 contains an array populated with data from Columns A & B:
Code:
[COLOR=SeaGreen]Column A[/COLOR] | [COLOR=Sienna]Column B[/COLOR]
[COLOR=SeaGreen]Apple[/COLOR] | [COLOR=Sienna]Pie[/COLOR]
[COLOR=SeaGreen]Apple[/COLOR] | [COLOR=Sienna]Pie[/COLOR]
[COLOR=SeaGreen]Kiwi[/COLOR] | [COLOR=Sienna]Tart[/COLOR]
[COLOR=SeaGreen]Apple[/COLOR] | [COLOR=Sienna]Tart[/COLOR]
[COLOR=SeaGreen]Peach[/COLOR] | [COLOR=Sienna]Pie[/COLOR]
Code:
[COLOR=SeaGreen]Column A[/COLOR] | [COLOR=Sienna]Column B[/COLOR] | [COLOR=Blue]Column E[/COLOR]
[COLOR=SeaGreen]Cherry[/COLOR] | [COLOR=Sienna]Pie[/COLOR] | [COLOR=Blue]Zebra[/COLOR]
[COLOR=SeaGreen]Apple[/COLOR] | [COLOR=Sienna]Pie [/COLOR] | [COLOR=Blue]Lion[/COLOR]
[COLOR=SeaGreen]Apple[/COLOR] | [COLOR=Sienna]Tart[/COLOR] | [COLOR=Blue]Giraffe[/COLOR]
[COLOR=SeaGreen]Peach[/COLOR] | [COLOR=Sienna]Pie[/COLOR] | [COLOR=Blue]Gazelle[/COLOR]
[COLOR=SeaGreen]Apple[/COLOR] | [COLOR=Sienna]Pie[/COLOR] | [COLOR=Blue]Elephant[/COLOR]
After running the macro, Sheet1 should appear as follows:
Code:
[COLOR=SeaGreen]Column A[/COLOR] | [COLOR=Sienna]Column B[/COLOR] | [COLOR=Purple]Column C[/COLOR]
[COLOR=SeaGreen]Apple[/COLOR] | [COLOR=Sienna]Pie [/COLOR] | [COLOR=Purple]Lion[/COLOR]
[COLOR=SeaGreen]Apple[/COLOR] | [COLOR=Sienna]Pie[/COLOR] | [COLOR=Purple]Elephant[/COLOR]
[COLOR=SeaGreen]Kiwi[/COLOR] | [COLOR=Sienna]Tart |[/COLOR] << Empty because 'Kiwi Tart' was not found in Array2
[COLOR=SeaGreen]Apple[/COLOR] | [COLOR=Sienna]Tart[/COLOR] | [COLOR=Purple]Giraffe[/COLOR]
[COLOR=SeaGreen]Peach[/COLOR] | [COLOR=Sienna]Pie[/COLOR] | [COLOR=Purple]Gazelle[/COLOR]
Code:
[COLOR=SeaGreen]Column A[/COLOR] | [COLOR=Sienna]Column B[/COLOR] | [COLOR=Blue]Column E[/COLOR]
[COLOR=SeaGreen]Cherry[/COLOR] | [COLOR=Sienna]Pie[/COLOR] | [COLOR=Blue]Zebra[/COLOR]
I'm not sure how to determine what row an array element resides. For example a search for Peach + Pie in array2 might tell me that both terms exists on the same row but how can I tell that both values are located on Row 6?
Any suggestions would be greatly appreciated!