moving pages from one workbook to another fast

Volly

New Member
Joined
Apr 24, 2013
Messages
41
I have 2 workbooks I want to combine into one. One has 100 sheets and the other has 89 sheets. I'd like to do it with a macro to speed it up.
I tried to use the macro recorder to so it however when I run the macro again I get an out of range error. WHen I look at the code I see this:
Code:
Sub Macro1()'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+t
'
    Sheets("Monthly_ADB__c-Monthly ADB La1").Select
    Sheets("Monthly_ADB__c-Monthly ADB La1").Move After:=Workbooks( _
        "Page layouts.xlsx").Sheets(102)
    Windows("Layout_6_25_2019 2_05 PM.xls").Activate
End Sub
In looking at the code I see what the issue is. It is specifying the sheet it wants to go to. Well, if it is already moved to the other workbook then it will throw the error.
My question is - how can I put my list of sheets in an array so I can move them in one go or just have it read the list of pages and pick the first one and move it, then repeat? Thanks in advance.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Are you combining all 189 sheets in a new workbook?
 
Upvote 0
try this:

sub moveworksheets()

dim ws as worksheet

for each ws in workbook("Monthly_ADB__c-Monthly ADB La1")
ws.select
ws.move after:=Workbooks("Page layouts.xlsx).sheets(102)
workbook("Monthly_ADB__c-Monthly ADB La1")
next ws
end sub
 
Upvote 0
Are there more than 89 sheets in the second workbook?
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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