I have small set of data in excel with 4 columns
File A:
SNO TYPE CountryA CountryB CountryD
1 T1 A1 B2 D1
2 T2 A2 B2 D2
and i have this data in another excel file
File B:
SNO TYPE CountryB CountryA CountryC
11 T10 B10 A10 C10
22 T20 B20 A20 C20
33 T30 B30 A30 C30
Now if i want to paste the data in file B over the data in file A, i want the column names to align automatically using some vba code.
So the End result should look like,
SNO TYPE CountryA CountryB CountryC CountryD
1 T1 A1 B1 -- D1
2 T2 A2 B2 -- D2
11 T10 A10 B10 C10 --
22 T20 A20 B20 C20 --
33 T30 A30 B30 C30 --
This should work for you:
It’s funny, I have this feeling there is a really easy non-VBA way to do this – but I couldn’t find the button for it on google. This will work for columns A to Z on sheets 1 and 2. This assumes your headers are in row 1.
EDIT – IN ADDITION:
I noticed that you wanted to do this with files and you didn’t say anything about sheets. This is how you would do it with different workbooks:
So if were heart-set on working with different .xls files, then that is how yo would do that. You obviously would just need to adjust the file path to whatever your paste-into file would be.