Copy Sheet1, Sheet2, Sheet3 to new Workbook

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi,

I want to copy 3 specific worksheets (Sheet1, Sheet2, Sheet3) to a new workbook. Only want to copy values and formatting, no formulas or references.

I want to call the new workbook "Eddie" and the current date.

thanks!
 
Last edited:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
.
Try this :

Code:
Option Explicit


Sub Seperate_Sheets()


Dim Path1 As String


Path1 = ActiveWorkbook.Path & "\" & "Eddie" & Format(Now, " dd-mm-yyyy ")


Sheets(Array("sheet1", "sheet2", "sheet3")).Copy
    ActiveWorkbook.SaveAs Filename:=Path1, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWindow.Close


End Sub
 
Upvote 0
Another option:
Code:
Sub CopySheets()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Copy
    For Each ws In Sheets
        ws.UsedRange.Value = ws.UsedRange.Value
    Next ws
    ActiveWorkbook.SaveAs Filename:="C:\Test\Eddie" & Replace(Date, "/", "-") & ".xlsx" 'change path to suit your needs
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
@ Logit your code errors out on the path1 line at Format
@mumps works great. How do give the option of where to save? Also is there a way to delete a command button when copying?
 
Upvote 0
.
Interesting .. it works without error here.

Try replacing the existing line of code with this one :
Code:
Path1 = ActiveWorkbook.Path & "\" & "Eddie " & Format(Now, "dd-mm-yyyy")


The only difference is the "dd-mm-yyy" portion. Previously a space existed before dd and after yyyy


 
Upvote 0
.
You might also try :

Code:
Format(Now(), "dd-mm-yyyy")
 
Upvote 0
To save to a different folder, just change the folder path where indicated in the code. Is there a command button on all 3 sheets or just one sheet? If one sheet, what is the sheet name?
 
Upvote 0
Assuming that the button name is "CommandButton1", try:
Code:
Sub CopySheets()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, sPath As String
    Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Copy
    For Each ws In Sheets
        ws.UsedRange.Value = ws.UsedRange.Value
    Next ws
    Sheets("Sheet1").Shapes("CommandButton1").Delete
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            sPath = .SelectedItems(1)
            ActiveWorkbook.SaveAs Filename:=sPath & Application.PathSeparator & "Eddie" & Replace(Date, "/", "-") & ".xlsx"
            Cancel = True
        End If
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
getting an overflow error at ws.UsedRange.Value = ws.UsedRange.Value

Is this because there are more worksheets that aren't being copied?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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