Move sheets to new workbook and save

Valentin

Board Regular
Joined
Oct 29, 2010
Messages
96
Office Version
  1. 365
Platform
  1. Windows
I need a macro to move all sheets except last sheet to new workbook and save the new workbook
 
your solution is almost correct, only the order of the sheets in newWorkbook is wrong. Have found another solution

VBA Code:
 Set wb1 = ThisWorkbook
    lastShName = wb1.Sheets(Sheets.Count).Name
    Set wb2 = Workbooks.Add

    For Each ws In wb1.Sheets
        If ws.Name <> lastShName Then
            ws.Move After:=wb2.Sheets(wb2.Sheets.Count)
        End If
    Next ws
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Is it possible to show your solution in here?
Thanks
 
Upvote 0
VBA Code:
Set wb1 = ThisWorkbook
    lastShName = wb1.Sheets(Sheets.Count).Name
    Set wb2 = Workbooks.Add

    For Each ws In wb1.Sheets
        If ws.Name <> lastShName Then
            ws.Move After:=wb2.Sheets(wb2.Sheets.Count)
        End If
    Next ws
 
Last edited by a moderator:
Upvote 0
Solution
Where do you see "Copy" in code?
VBA Code:
Sub Delete_Last_Sheet()
    Application.DisplayAlerts = False
    Sheets(Sheets.Count).Delete
    Call SaveFile_WithNewName
End Sub
Sub SaveFile_WithNewName()
    Dim newName As String
    newName = "NewWorkbook"
    ActiveWorkbook.SaveAs Filename:=newName
End Sub
 
Upvote 0
The word "copy" is not in your code but all sheets except the last one will be COPIED to the new workbook. in the code I suggested, all sheets except the last sheet are MOVED to the new workbook and only the last sheet remains in the first workbook.
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

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