The code below for some reason says out of context where I am trying to delete then replace tabs.

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
VBA Code:
Option Explicit

Sub CopySheets()

Dim AutomatedCardworkerWorkbook As Workbook
Dim JobCardMasterWorkbook As Workbook
Dim JobCardMasterWorksheets As Worksheet



Set AutomatedCardworkerWorkbook = Workbooks("Automated Cardworker")
Set JobCardMasterWorkbook = Workbooks("1 Page Job Card Master")
Set JobCardMasterWorksheets = JobCardMasterWorkbook.Sheets("Job Card Master")

Application.DisplayAlerts = False

AutomatedCardworkerWorkbook.Sheets("Job Card Master").Delete
AutomatedCardworkerWorkbook.Sheets("Job Card with Time Analysis").Delete
AutomatedCardworkerWorkbook.Sheets("Check Sheet").Delete
AutomatedCardworkerWorkbook.Sheets("SPEC SHEET").Delete
AutomatedCardworkerWorkbook.Sheets("Electrical inspection").Delete
AutomatedCardworkerWorkbook.Sheets("PRE ASSEMBLY3").Delete
AutomatedCardworkerWorkbook.Sheets("TOOLPOD").Delete
AutomatedCardworkerWorkbook.Sheets("FAB SHOP").Delete
AutomatedCardworkerWorkbook.Sheets("STOCK LIST").Delete
AutomatedCardworkerWorkbook.Sheets("ORDER LIST").Delete
AutomatedCardworkerWorkbook.Sheets("PRE-DEL").Delete
AutomatedCardworkerWorkbook.Sheets("WOOD SHOP").Delete
AutomatedCardworkerWorkbook.Sheets("Electrical load analysis").Delete

For Each JobCardMasterWorksheets In JobCardMasterWorkbook.Sheets
JobCardMasterWorksheets.Copy After:=AutomatedCardworkerWorkbook.Sheets(AutomatedCardworkerWorkbook.Sheets.Count)
Next
Application.DisplayAlerts = True
End Sub
 
Last edited by a moderator:
Maybe
VBA Code:
Sub CopySheets()

Dim AutomatedCardworkerWorkbook As Workbook
Dim JobCardMasterWorkbook As Workbook
Dim JobCardMasterWorksheets As Worksheet
Dim Ws As Worksheet


Set AutomatedCardworkerWorkbook = Workbooks("Automated Cardworker")
Set JobCardMasterWorkbook = Workbooks("1 Page Job Card Master")
Set JobCardMasterWorksheets = JobCardMasterWorkbook.Sheets("Job Card Master")

Application.DisplayAlerts = False

AutomatedCardworkerWorkbook.Sheets("Job Card Master").Delete
AutomatedCardworkerWorkbook.Sheets("Job Card with Time Analysis").Delete
AutomatedCardworkerWorkbook.Sheets("Check Sheet").Delete
AutomatedCardworkerWorkbook.Sheets("SPEC SHEET").Delete
AutomatedCardworkerWorkbook.Sheets("Electrical inspection").Delete
AutomatedCardworkerWorkbook.Sheets("PRE ASSEMBLY3").Delete
AutomatedCardworkerWorkbook.Sheets("TOOLPOD").Delete
AutomatedCardworkerWorkbook.Sheets("FAB SHOP").Delete
AutomatedCardworkerWorkbook.Sheets("STOCK LIST").Delete
AutomatedCardworkerWorkbook.Sheets("ORDER LIST").Delete
AutomatedCardworkerWorkbook.Sheets("PRE-DEL").Delete
AutomatedCardworkerWorkbook.Sheets("WOOD SHOP").Delete
AutomatedCardworkerWorkbook.Sheets("Electrical load analysis").Delete

For Each Ws In JobCardMasterWorkbook.Sheets
   JobCardMasterWorksheets.Copy After:=AutomatedCardworkerWorkbook.Sheets(AutomatedCardworkerWorkbook.Sheets.Count)
Next Ws
Application.DisplayAlerts = True
End Sub
The workbook needs to be chosen from the Listbox3 on the userform
The list of Sheets to delete I need the whole lot entered back in to the Automated Jobcard from new worksheet. I tried it and all I get is "Job Card Master"
Can you specify all worksheets from a workbook using this line of code

Set JobCardMasterWorksheets = JobCardMasterWorkbook.Sheets("1,2,3,4,5" ect)
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
The workbook needs to be chosen from the Listbox3 on the userform
And where did you mention this?
The list of Sheets to delete I need the whole lot entered back in to the Automated Jobcard from new worksheet. I tried it and all I get is "Job Card Master"
Do all those sheets exist in this workbook
VBA Code:
Workbooks("1 Page Job Card Master")
 
Upvote 0
And where did you mention this? Sorry I did not say this as I have only just decided to do it this way.
Do all those sheets exist in this workbook Yes there are 5 workbooks to choose from the listbox3 but all the tabs are the same name
 
Upvote 0
Oops forgot to change part of it
VBA Code:
For Each Ws In JobCardMasterWorkbook.Sheets
   Ws.Copy After:=AutomatedCardworkerWorkbook.Sheets(AutomatedCardworkerWorkbook.Sheets.Count)
Next Ws
 
Upvote 0
I`ve tried to add a item from listbox3 to my code it is not working please help.
 
Upvote 0
This is now a totally different question, so you will need to start a new thread.
Is you original question solved?
 
Upvote 0

Forum statistics

Threads
1,215,581
Messages
6,125,656
Members
449,246
Latest member
jbbtz28

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