Copying worksheets from one workbook to another based on a list

ath

New Member
Joined
Dec 10, 2020
Messages
8
Hello,

I am trying to get some code working where I can copy worksheets from one workbook into another based on a list. Here is the code i have put together so far:

Dim Sht As Worksheet
Dim sheet_names As Variant
Dim destWB As Workbook
Set destWB = ThisWorkbook

sheet_names = OpenBook.Sheets("CaseList").Range("C2:C2000").Value

For Each Sht In OpenBook.Sheets

If Not IsError(Application.Match(Sht.Name, sheet_names, 0)) Then

Sht.Copy After:=destWB.Sheets(Sheets.Count)

End If

Next Sht

When i run the code, i get a runtime error 424 message. Any help would be appreciated.

Thanks
 
Odd things is that i was running it from the destination workbook as well. Either way, it works now. Thanks again for your assistance.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,375
Messages
6,119,166
Members
448,870
Latest member
max_pedreira

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