VBA copy sheets as values only

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
184
Office Version
  1. 2013
Morning All,

I have tabs “Info”, “Dash”, “Projects”, Dates” and “DatesInfo”.

I would like to copy them to a new workbook with the same formatting but values only to remove the formulas. I would like to save the file name as ‘Performance Dashboard - DD/MM/YYYY’ with today’s date in the same directory as the original.

Many thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try:
Code:
Sub CopySheets()
    Application.ScreenUpdating = False
    Dim srcWB As Workbook, desWB As Workbook, ws As Worksheet
    Set srcWB = ThisWorkbook
    Set desWB = Workbooks.Add(1)
    With srcWB
        For Each ws In .Sheets(Array("Info", "Dash", "Projects", "Dates", "DatesInfo"))
            With desWB
                ws.Copy .Sheets(.Sheets.Count)
                ActiveSheet.UsedRange.Cells.Value = ActiveSheet.UsedRange.Cells.Value
            End With
        Next ws
    End With
    Application.DisplayAlerts = False
    Sheets("Sheet1").Delete
    Application.DisplayAlerts = True
    ActiveWorkbook.SaveAs Filename:=srcWB.Path & Application.PathSeparator & "Performance Dashboard - " & Format(Date, "dd-mm-yyyy")
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi @mumps, thank you.

That's seems to do the job but I forgot that some of the sheets have protected cells, and I would like to carry over the protection too.

The error is" Run-time error '1004': The cell or chart you're trying to change is on a protected sheet".

Many thanks again. :)
 
Upvote 0
Are the sheets password protected? Are they all protected or just some? If some, which ones are protected?
 
Upvote 0
Try the following macro. Replace "MyPassword" (in red) with your actual password.
Code:
Sub CopySheets()
    Application.ScreenUpdating = False
    Dim srcWB As Workbook, desWB As Workbook, ws As Worksheet
    Set srcWB = ThisWorkbook
    Set desWB = Workbooks.Add(1)
    With srcWB
        For Each ws In .Sheets(Array("Info", "Dash", "Projects", "Dates", "DatesInfo"))
            ws.Unprotect Password:="[COLOR="#FF0000"]MyPassword[/COLOR]"
            With desWB
                ws.Copy .Sheets(.Sheets.Count)
                ActiveSheet.UsedRange.Cells.Value = ActiveSheet.UsedRange.Cells.Value
            End With
            ws.Protect Password:="[COLOR="#FF0000"]MyPassword[/COLOR]"
        Next ws
    End With
    Application.DisplayAlerts = False
    Sheets("Sheet1").Delete
    Application.DisplayAlerts = True
    ActiveWorkbook.SaveAs Filename:=srcWB.Path & Application.PathSeparator & "Performance Dashboard - " & Format(Date, "dd-mm-yyyy")
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,937
Members
448,534
Latest member
benefuexx

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