I'm making a table with all the dates in a month. The user picks month and year. I have just the code listed below that calculates leap year for February and all other months of any year. The problem is that it does not calculate February during a non-leap year. The Application-defined or object-defined error message comes up during the autofill part of my code. I bolded the code that triggers the error message. Anything helps!
If monthNum=11 Or monthNum=4 Or monthNum=9 Or monthNum= 6 Then
numDays=30
ElseIf monthNum=2 Then
If year Mod 4 =0 Then
If year Mod 100= 0 Then
If year Mod 400= Then
numDays= 28
Else
numDays =29
End If
numDays=28
Else
numDays=29
End If
End If
Else
numDays=31
End If
Range("A6")=DateSerial(year, monthNum, 1)
Range("A6").Autofill Destination:=Range("A6").Resize(numDays, 1), Type:=xlFillDefault
If monthNum=11 Or monthNum=4 Or monthNum=9 Or monthNum= 6 Then
numDays=30
ElseIf monthNum=2 Then
If year Mod 4 =0 Then
If year Mod 100= 0 Then
If year Mod 400= Then
numDays= 28
Else
numDays =29
End If
numDays=28
Else
numDays=29
End If
End If
Else
numDays=31
End If
Range("A6")=DateSerial(year, monthNum, 1)
Range("A6").Autofill Destination:=Range("A6").Resize(numDays, 1), Type:=xlFillDefault