Hi
I have a workbook that I use for inventory tracking. I make a copy of the last worksheet almost every day and name it todays date. After some time the workbook becomes very large and slow to work with. I am therefore trying to create a macro that will move all previous months sheets to a new workbook.
This is the code I have come up with so far:
I have created a formula in E1 that extracts the sheet name and checks wether the month is the same as the current month. This way it will only archive the old sheets.
The part I can't understand is that if I replace "ActiveWindow.SelectedSheets.Copy" with "ActiveWindow.SelectedSheets.Visible = xlSheetHidden" it works as I want it to and hides the old sheets but when I try to copy them it copies all the worksheets in the workbook and not just the old ones.
Any suggestions?
I have a workbook that I use for inventory tracking. I make a copy of the last worksheet almost every day and name it todays date. After some time the workbook becomes very large and slow to work with. I am therefore trying to create a macro that will move all previous months sheets to a new workbook.
This is the code I have come up with so far:
Code:
Sub autoarchive()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If UCase(wks.Range("E1").Value) = UCase("FALSE") Then
wks.Select False
End If
Next wks
'Move selected worksheets to new workbook
If ThisWorkbook.Sheets.Count < 2 Then
Exit Sub
Else
ActiveWindow.SelectedSheets.Copy
End If
End Sub
I have created a formula in E1 that extracts the sheet name and checks wether the month is the same as the current month. This way it will only archive the old sheets.
The part I can't understand is that if I replace "ActiveWindow.SelectedSheets.Copy" with "ActiveWindow.SelectedSheets.Visible = xlSheetHidden" it works as I want it to and hides the old sheets but when I try to copy them it copies all the worksheets in the workbook and not just the old ones.
Any suggestions?