Hi there, I am trying to create a new workbook for each worksheet in an existing file with the resulting workbooks maintaining the formats but no formulas. I am using trying to use the below code but get errors at the pastespecial line codes. Is this something someone can help with?
Private Sub CommandButton1_Click()
Dim a As Integer
Dim ws As Worksheet
Dim wb As Workbook
a = ThisWorkbook.Worksheets.Count
For i = 1 To a
If ThisWorkbook.Worksheets(i).Name <> "Cells to review" Then
'If InStr(ThisWorkbook.Worksheets(i).Name, <> "Cell") Then
Set wb = Workbooks.Add
ThisWorkbook.Worksheets(i).Copy before:=wb.Worksheets(1)
ThisWorkbook.Worksheets(i).PasteSpecial xlPasteValues
ThisWorkbook.Worksheets(i).PasteSpecial xlPasteFormats
wb.SaveAs "C:\P&L-Summary" & "\" & ActiveSheet.Name & ".xlsm", 52
wb.Close savechanges = True
End If
Next i
ThisWorkbook.Activate
ThisWorkbook.Worksheets("Cells to review").Activate
ThisWorkbook.Worksheets("Cells to review").Cells(1, 1).Select
MsgBox ("Files created")
End Sub
Private Sub CommandButton1_Click()
Dim a As Integer
Dim ws As Worksheet
Dim wb As Workbook
a = ThisWorkbook.Worksheets.Count
For i = 1 To a
If ThisWorkbook.Worksheets(i).Name <> "Cells to review" Then
'If InStr(ThisWorkbook.Worksheets(i).Name, <> "Cell") Then
Set wb = Workbooks.Add
ThisWorkbook.Worksheets(i).Copy before:=wb.Worksheets(1)
ThisWorkbook.Worksheets(i).PasteSpecial xlPasteValues
ThisWorkbook.Worksheets(i).PasteSpecial xlPasteFormats
wb.SaveAs "C:\P&L-Summary" & "\" & ActiveSheet.Name & ".xlsm", 52
wb.Close savechanges = True
End If
Next i
ThisWorkbook.Activate
ThisWorkbook.Worksheets("Cells to review").Activate
ThisWorkbook.Worksheets("Cells to review").Cells(1, 1).Select
MsgBox ("Files created")
End Sub