Copying range from every sheet in 1 workbook to another?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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