Copying columns from Sheet1 to Sheet2 based on column names

AVAYA123456

New Member
Joined
Jun 24, 2015
Messages
3
Hi Everyone,

I have a requirement to copy data from Sheet A to Sheet B. But the constraint is as below.

1. Sheet A has more columns than Sheet B. I have to copy only few columns to Sheet B from sheet A.
2. There is a mapping in another control sheet available to what cols from Sheet A should go to Sheet B.

Example:
Sheet A has columns - "First Name", "Last Name", "Address", "City", "State", "ZIP", "Emp ID", "DOJ"
Sheet B has columns - "Employee ID", "Last Name", "First Name", "Date of Joining"

Mapping provided:

Sheet A --> Sheet B
________________________
"Emp ID" --> "Employee ID"
"Last Name" --> "Last Name"
"First Name" --> "First Name"
"DOJ" --> "Date of Joining"

so based on column names provided, I have to move only specific columns from Sheet A to B. Can you please help me on this. Thanks.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try this:

Code:
Sub Copy_Columns()
Application.ScreenUpdating = False
Sheets("A").Columns(1).Copy Destination:=Sheets("B").Columns(3)
Sheets("A").Columns(2).Copy Destination:=Sheets("B").Columns(2)
Sheets("A").Columns(7).Copy Destination:=Sheets("B").Columns(1)
Sheets("A").Columns(8).Copy Destination:=Sheets("B").Columns(4)
Application.ScreenUpdating = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,268
Messages
6,123,966
Members
449,137
Latest member
yeti1016

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