Copying 3 worksheets to a new workbook

jimmy2times

Board Regular
Joined
Aug 8, 2014
Messages
69
Hello,

I have the following code which is 99% working as intended

Sub ThreeSheets()
'Turn off screen updating
Application.ScreenUpdating = False


'Make the hidden worksheets unhidden so I can copy them
Worksheets("April Performance").Visible = True
Worksheets("May Performance").Visible = True


'Open With Structure to set page layout
With Worksheets("June Performance").PageSetup
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
.PaperSize = xlPaperA3
.Orientation = xlLandscape
End With


'Open a With structure
'Copy the worksheets listed in the array into a newly created workbook
'Put them before sheet 1
'Hide sheet 1
With ActiveWorkbook.Sheets(Array("April Performance", "May Performance", "June Performance"))
.Copy _
before:=Workbooks.Add.Worksheets(1)
ActiveWorkbook.Sheets("Sheet1").Visible = xlSheetVeryHidden
End With


'Activate the existing workbook and hide the tabs I want to be hidden
ThisWorkbook.Activate
Worksheets("April Performance").Visible = False
Worksheets("May Performance").Visible = False


'Turn on screen updating
Application.ScreenUpdating = True
End Sub

The only issue is that April and May performance contain formulas and I want to paste special values for these worksheets in the new workbook. I add in the following code before turning the screen update back on
With ActiveWorkbook.Sheets(Array("April Performance", "May Performance"))
.Cells.PasteSpecial xlValues
.Cells.PasteSpecial xlFormats
End With

This is giving me a run time error "Object doesn't support this property or method"

Can anyone help me with the last piece of code so I can paste special values for the worksheets specified in the new workbook.

Many Thanks
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try:
Code:
Sub Three_Sheets()

    Dim wkb     As Workbook
    
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With
    
    Sheets("April Performance").Visible = True
    Sheets("May Performance").Visible = True

    With Sheets("June Performance")
        .Zoom = False
        .FitToPagesTall = 1
        .FitToPagesWide = 1
        .PaperSize = xlPaperA3
        .Orientation = xlLandscape
    End With
    
    With Sheets(Array("April Performance", "May Performance", "June Performance"))
        .Copy before:=Workbooks.add.Sheets(1)
        .Sheets("Sheet1").Delete
    End With
    Set wkb = ActiveWorkbook
    
    With wkb
        .Sheets("April performance").Cells.Value = .Sheets("April performance").Cells.Value
        .Sheets("May performance").Cells.Value = .Sheets("May performance").Cells.Value
    End With
    
    With ThisWorkbook
        .Sheets("April Performance").Visible = False
        .Sheets("May Performance").Visible = False
        .Activate
    End With
    
    With Application
        .CutCopyMode = False
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
    
    Set wkb = Nothing
    
End Sub
 
Last edited:
Upvote 0
Thanks for trying but still copying the formulas not the values.

I have the following code which is 99% working as intended

Sub ThreeSheets()
'Turn off screen updating
Application.ScreenUpdating = False


'Make the hidden worksheets unhidden so I can copy them
Worksheets("April Performance").Visible = True
Worksheets("May Performance").Visible = True


'Open With Structure to set page layout
With Worksheets("June Performance").PageSetup
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
.PaperSize = xlPaperA3
.Orientation = xlLandscape
End With


'Open a With structure
'Copy the worksheets listed in the array into a newly created workbook
'Put them before sheet 1
'Hide sheet 1
With ActiveWorkbook.Sheets(Array("April Performance", "May Performance", "June Performance"))
.Copy _
before:=Workbooks.Add.Worksheets(1)
ActiveWorkbook.Sheets("Sheet1").Visible = xlSheetVeryHidden
End With


'Activate the existing workbook and hide the tabs I want to be hidden
ThisWorkbook.Activate
Worksheets("April Performance").Visible = False
Worksheets("May Performance").Visible = False


'Turn on screen updating
Application.ScreenUpdating = True
End Sub

The only issue is that April and May performance contain formulas and I want to paste special values for these worksheets in the new workbook. I add in the following code before turning the screen update back on
With ActiveWorkbook.Sheets(Array("April Performance", "May Performance"))
.Cells.PasteSpecial xlValues
.Cells.PasteSpecial xlFormats
End With

This is giving me a run time error "Object doesn't support this property or method"

Can anyone help me with the last piece of code so I can paste special values for the worksheets specified in the new workbook.

Many Thanks[/QUOTE]
 
Upvote 0
Just tested this and it works in creating a new workbook with 3 sheets and all formula values are hardcoded:
Code:
Sub Three_Sheets()
    
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With
    
    Sheets("April Performance").Visible = True
    Sheets("May Performance").Visible = True

    With Sheets("June Performance")
        .Zoom = False
        .FitToPagesTall = 1
        .FitToPagesWide = 1
        .PaperSize = xlPaperA3
        .Orientation = xlLandscape
    End With
    
    Sheets(Array("April Performance", "May Performance", "June Performance")).Copy before:=Workbooks.add.Sheets(1)
    
    With ActiveWorkbook
        .Sheets("April performance").UsedRange.Value = .Sheets("April performance").UsedRange.Value
        .Sheets("May performance").UsedRange.Value = .Sheets("May performance").UsedRange.Value
    End With
    
    With ThisWorkbook
        .Sheets("April Performance").Visible = False
        .Sheets("May Performance").Visible = False
        .Activate
    End With
    
    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
    
End Sub
 
Last edited:
Upvote 0
Cheers Jack this seems to work

Sub Three_Sheets()

With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With

Sheets("April Performance").Visible = True
Sheets("May Performance").Visible = True

With Sheets("June Performance")
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
.PaperSize = xlPaperA3
.Orientation = xlLandscape
End With

Sheets(Array("April Performance", "May Performance", "June Performance")).Copy before:=Workbooks.add.Sheets(1)

With ActiveWorkbook
.Sheets("April performance").UsedRange.Value = .Sheets("April performance").UsedRange.Value
.Sheets("May performance").UsedRange.Value = .Sheets("May performance").UsedRange.Value
End With

With ThisWorkbook
.Sheets("April Performance").Visible = False
.Sheets("May Performance").Visible = False
.Activate
End With

With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With

End Sub[/code][/QUOTE]
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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