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
 

ath

New Member
Joined
Dec 10, 2020
Messages
8
Odd things is that i was running it from the destination workbook as well. Either way, it works now. Thanks again for your assistance.
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Watch MrExcel Video

Forum statistics

Threads
1,123,346
Messages
5,601,080
Members
414,426
Latest member
fraru

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
Top