Hello, I am trying to create a macro which copies and pastes the last 3 Spreadsheets of a Workbook into a new one. Anyone has any ideas of how this can be accomplished? What I've tried so far does not work.
Sub t()
Dim Oldwb As Workbook, Newwb As Workbook
Set Oldwb = Workbooks(1)
Set Newwb = Workbooks(2)
For i = 1 To 3
Oldwb.Sheets(Oldwb.Sheets.Count - i).Copy After:=Newwb.Sheets(Sheets.Count)
Next
End Sub
Sub CopySheets()
Dim wbNew As Workbook
Set wbNew = Workbooks.Add(1)
With ThisWorkbook
.Worksheets(Array(.Sheets.Count, .Sheets.Count - 1, .Sheets.Count - 2)).Copy _
After:=wbNew.Sheets(wbNew.Sheets.Count)
End With
End Sub
I ended up using ideas from both responses this is my code and it works:
Code:
'COPY AND SAVE'
Dim Oldwb As Workbook, Newwb As Workbook
Set Oldwb = Workbooks("Saxco COSR Test 25.xlsm")
Set Newwb = Workbooks.Add(1)
For i = 1 To 3
Oldwb.Sheets(Oldwb.Sheets.Count + 1 - i).Copy Before:=Newwb.Sheets(Sheets.Count)
Next
Oldwb.Close SaveChanges:=True
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.