hello, I have a workbook with worksheets named after dates. I want to deleate all worksheets older than the first day of the last month. How would you suggest I do it? This is my current code.
Sub test()
Dim date1 As Date
Dim date2 As Date
Dim dd As Date
Dim ws As Worksheet
date1 = DateSerial(Year(Date), Month(Date) - 1, 1)
date2 = Date
For dd = date1 To date2
Debug.Print Format(dd, "YYMMDD")
Next dd
'For Each ws In Worksheets
'
'If not ws.Name = dd Then
' ws.Delete
' End If
'Next ws
End Sub
Sub test()
Dim date1 As Date
Dim date2 As Date
Dim dd As Date
Dim ws As Worksheet
date1 = DateSerial(Year(Date), Month(Date) - 1, 1)
date2 = Date
For dd = date1 To date2
Debug.Print Format(dd, "YYMMDD")
Next dd
'For Each ws In Worksheets
'
'If not ws.Name = dd Then
' ws.Delete
' End If
'Next ws
End Sub