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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
.
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
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
I wanted give give the option of where to save. The command button is only on sheet1. Thanks!!
 
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,216,085
Messages
6,128,733
Members
449,465
Latest member
TAKLAM

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