import specific columns from one workbook to another from matching header with vba

rkb1510

New Member
Joined
Oct 24, 2024
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
How can I import/copy columns based on their header name from one excel workbook to another excel workbook using macro/VBA code.
EX: Source WB
[TR]
[th width="var(--_ta-th-w)"]Column A[/th][th width="var(--_ta-th-w)"]Column B[/th][th width="var(--_ta-th-w)"]Column C[/th][th width="var(--_ta-th-w)"]Column D[/th]
[/TR]
[TR]
[td width="var(--_ta-td-w)"]Cell 1[/td][td width="var(--_ta-td-w)"]Cell 2[/td][td width="var(--_ta-td-w)"]Cell 3[/td][td width="var(--_ta-td-w)"]Cell 4[/td]
[/TR]
[TR]
[td width="var(--_ta-td-w)"]Cell 5[/td][td width="var(--_ta-td-w)"]Cell 6[/td][td width="var(--_ta-td-w)"]Cell 7[/td][td width="var(--_ta-td-w)"]Cell 8[/td]
[/TR]
Target WB
[TR]
[th width="var(--_ta-th-w)"]Column B[/th][th width="var(--_ta-th-w)"]Column D[/th]
[/TR]
[TR]
[td width="var(--_ta-td-w)"]Cell x[/td][td width="var(--_ta-td-w)"]Cell y[/td]
[/TR]
[TR]
[td width="var(--_ta-td-w)"]Cell x[/td][td width="var(--_ta-td-w)"]Cell y[/td]
[/TR]
Output should be updating Target WB with data of columns from source WB as below
[TR]
[th width="var(--_ta-th-w)"]Column B[/th][th width="var(--_ta-th-w)"]Column D[/th]
[/TR]
[TR]
[td width="var(--_ta-td-w)"]Cell 2[/td][td width="var(--_ta-td-w)"]Cell 4[/td]
[/TR]
[TR]
[td width="var(--_ta-td-w)"]Cell 6[/td][td width="var(--_ta-td-w)"]Cell 8[/td]
[/TR]
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Welcome to the MrExcel board!

I suggest that you investigate XL2BB for providing sample data
(If you have trouble with XL2BB, review the "XL2BB Icons greyed out" link in the 'Known XL2BB issues' section near the top of the XL2BB Instructions page linked above.)
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,114
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top