I have two excel spreadsheets, one contains data on various persons, while the other is more of an index.
The ‘Index’ spreadsheet is laid out as following (as an example);
A B
1 [person:][pID: ]
2 [Mark ][1 ]
3 [James ][2 ]
4 [John ][3 ]
5 [David ][4 ]
n [ ... ][n ]
The ‘Data’ spreadsheet is laid out as following (as an example);
A
1 [pID: ][ ...
2 [David ][ ...
3 [David ][ ...
4 [David ][ ...
5 [James ][ ...
6 [Mark ][ ...
7 [David ][ ...
n [ ... ][ ...
What I would like to do is replace the column A in the ‘Data’ spreadsheet, with the corresponding index of the ‘Index’ spreadsheet, probably using VBA.
The result would be something like this;
A
1 [pID: ][ ...
2 [4 ][ ...
3 [4 ][ ...
4 [4 ][ ...
5 [2 ][ ...
6 [1 ][ ...
7 [4 ][ ...
n [ ... ][ ...
I have seen some static approaches which use a switch statement, but I’d really like to be able to import the data from another spreadsheet.
I’m trying not to resort to copy pasting and ‘Replace All’.
Thanks!
Try this:
Explanation:
NOTE:
Personally, I would leave the Raw data sheet as is and use a presentation sheet which looks up the data sheet and the index sheet and presents it how you want it. Then you wont necessarily need code and if you still do want to use code then the code will be much simpler. You will need to add code to turn off screen updating and use error handling etc.
An alternative to ja72’s solution:
quietly confident its faster too 😉