Macro to copy all rows from one tab to another, for selected columns to new column headings

Rosie1900

New Member
Joined
Feb 15, 2018
Messages
4
Hi, I have one workbook with two tabs - 'raw' & 'final'. I want to copy all rows from 'raw' onto 'final' - but only for selected columns. Also, the column headings in 'raw' aren't identical to the column headings in 'final' but can be mapped as they won't change, month to month.
In essence, I'm looking for a macro that is something along the lines of : for each row in 'raw', copy column 'name1' to column 'name_2'.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Which columns do you want to copy & which columns should they be copied to?
 
Upvote 0
Example of column names:

FROM "Street no & name" on tab "raw" TO "Street Address" on tab "final"
FROM "Expense_Office" on tab "raw" TO "OfficeCost" on tab "final"

But there are lots of columns that need to be moved - to be used in formulae on tab "final".
 
Upvote 0
Is this a possibility?
Code:
Sub AAAAA()
Dim arr1, arr2, a As Long, i As Long, ii As Long
Dim sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Worksheets("raw")
Set sh2 = Worksheets("final")
arr1 = Array("Street no & name", "Expense_Office")    '<----- Add as required
arr2 = Array("Street Address", "OfficeCost")    '<----- Add as required
    For a = LBound(arr1) To UBound(arr1)
        i = sh1.Rows(1).Find(arr1(a), , , 1).Column
        ii = sh2.Rows(1).Find(arr2(a), , , 1).Column
    With sh1
        .Range(.Cells(2, i), .Cells(.Cells(.Rows.Count, i).End(xlUp).Row, i)).Copy sh2.Cells(2, ii)
    End With
    Next a
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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