Thanks for your constructive comments. I'm not a big fan of multi-line statments using "space + underscore"
so that's one reason I don't use Iif very much unless speed is critical, which is not the case here. The other
reason I hardly use it is because I tend to forget it exists! I've not used VBA in almost sevenyears and I'm
quite rusty.Thanks for reminding me.
As for leap years, you are 100% correct. I was basing my assumption on the fact that a Sunday falling on
Dec. 31st in a leap year would be a rare occurrence. But I found one in the year 2028.
So I added some lines to check any year to see if its a leap year and extend the DaysInYear to 366 if it is.
Thanks for pointing this out.
Before showing my amended code, I want to show anyone that wants to play around with it, a block of
code that will delete all the sheets that were added to the workbook so they can run the code again
without closing the workbook.
It's best if you start with a new workbook and not have any other workbooks open so you don't delete sheets
from the wrong workbook. You must delete all worksheets until only one worksheet exists, then rename it
something like "sss".
- Code: Select all
Sub DeleteSheets()
Dim Sht As Worksheet, i As Integer
Application.DisplayAlerts = False
For Each Sht In ThisWorkbook.Worksheets
If Worksheets.Count = 1 Then Exit Sub
Sht.Delete
Next Sht
Application.DisplayAlerts = True
End Sub
See my next post with the amended code.