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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,216,136
Messages
6,129,084
Members
449,485
Latest member
greggy

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