VBA Macro to Copy/Paste Contents of Column Based on Header

JansiJansi

New Member
Joined
Jun 22, 2022
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hiya guys.

I am trying to build some conversion files for exports from other sites to match my company's imports. I am going to have to identify which header exists in the other company's export and match it to my company's header.

For example:
Export contains header "Product Name"
Import contains header "Title"

These are the same thing, so I'd want to copy the column containing the Product Name header and paste it into the column in the other workbook which contains the header Title.

I'm new to VBA and would appreciate any help. I've looked at some similar files from searches, but can't get it to work for mine. This leads me to believe my brains are dookie because it's a simple macro, I think.

Thank you!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I have a horizontal row of headers that I know I want with a defined name of CopyColumns. I have a formatted table, Table1, that shares the matching headers. This cycles through and pastes each column. Limited rows in my dataset.
VBA Code:
    Set copycolumns = Range("CopyColumns")
        For Each cell In copycolumns
            header = cell.Value
            Set pastelocation = cell.Offset(1)
         On Error GoTo skipover:
                Range("Table1[" & header & "]").Copy
                pastelocation.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
skipover:
On Error GoTo 0
        Next cell
 
Upvote 0

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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