Copying range from every sheet in 1 workbook to another?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
785
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have 2 very similar workbooks with same tab names.

I'm wanting to copy range (A1:S100) from every sheet in workbookA and paste at U1 in every relevant sheet in workbookB

Can do it with VBA one at a time but looking to see if it can be done in one go with a loop etc.

Any help appreciated
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Assumes both workbooks are open at run time. Also assumes code will run from workbookA
Code:
Sub t()
Dim wb1 As Workbook, wb2 As Workbook, sh As Worksheet, rng As Range
Set wb1 = Workbooks("WorkbookA.xlsm") 'Edit file name
Set wb2 = Workbooks("WorkbookB.xlsx") 'Edit file name
    For Each sh In wb1.Sheets
        Set rng = sh.Range("A1:S100")
        rng.Copy wb2.Sheets(sh.Name).Range("U1")
    Next
End Sub
Be sure to save your host workbook as a macroenabled workbook (.xlsm) to preserve the code. Note the comments for the workbook names.
 
Upvote 0
Assumes both workbooks are open at run time. Also assumes code will run from workbookA
Code:
Sub t()
Dim wb1 As Workbook, wb2 As Workbook, sh As Worksheet, rng As Range
Set wb1 = Workbooks("WorkbookA.xlsm") 'Edit file name
Set wb2 = Workbooks("WorkbookB.xlsx") 'Edit file name
    For Each sh In wb1.Sheets
        Set rng = sh.Range("A1:S100")
        rng.Copy wb2.Sheets(sh.Name).Range("U1")
    Next
End Sub
Be sure to save your host workbook as a macroenabled workbook (.xlsm) to preserve the code. Note the comments for the workbook names.

perfect thankyou it worked
 
Upvote 0

Forum statistics

Threads
1,215,568
Messages
6,125,599
Members
449,238
Latest member
wcbyers

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