Copy and paste worksheets

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
This code works fine except the worksheets end up a different order in the Destination.
Any way of stopping this?

VBA Code:
Private Sub Jobcard_Templates_Click()

TurnOff

    Dim wkbDest As Workbook
    Dim wkbSource As Workbook
    Dim ws As Worksheet
    Dim wsDest As Worksheet
    Dim wsJobCardAnalysis As Worksheet
    Dim CurrentSheet As Worksheet
    Dim sht As Worksheet
    Dim wsCount As Long
   
    Set wkbDest = Workbooks("Automated Cardworker.xlsm")
    Set wsDest = Worksheets("Job Card with Time Analysis")
    Set ws = ThisWorkbook.Worksheets("Job Card Master")
    Set wsJobCardAnalysis = ThisWorkbook.Worksheets("Job Card with Time Analysis")

   
    ws.Delete
    wsJobCardAnalysis.Delete
           
       
    Set wkbSource = Workbooks.Open("\\tgs-srv01\share\ShopFloor\PRODUCTION\DLS Cardworker\Jobcard Templates\" _
                         & Body_And_Vehicle_Type_Form.Jobcard_Templates.List(Body_And_Vehicle_Type_Form.Jobcard_Templates.ListIndex))

        For Each sht In Workbooks(wkbSource.Name).Sheets
           sht.Copy After:=Workbooks(wkbDest.Name).Sheets(5)
        Next sht
       
wkbSource.Close savechanges:=False

ThisWorkbook.Worksheets("Job Card Master").Activate

TurnOn


End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try changing
VBA Code:
    For Each sht In Workbooks(wkbSource.Name).Sheets
        sht.Copy After:=Workbooks(wkbDest.Name).Sheets(5)
    Next sht
to
VBA Code:
    Dim i As Long
    For i = wkbSource.Sheets.Count To 1 Step -1
        wkbSource.Sheets(i).Copy After:=wkbDest.Sheets(5)
    Next
 
Upvote 0
Solution
Just going out so afraid that I can't look at your other post
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
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