Place If-Statement in Macro?

  • Thread starter Thread starter theFrog
  • Start date Start date
T

theFrog

I'd like to automatically copy this If-Statement into a cell using a macro.

=IF(OR(C1="05",C1="07",C1="10",C1="12",C1="03",C1="01",C1="08"),"31",IF(OR(C
1="04",C1="06",C1="09",C1="11"),"30",IF(C1="02","29","")))

Thanks for your help.
Mike
 
There are far better ways to accomplish what you're trying to do, but
this will work:

Public Sub EnterLongFormula()
Selection.Formula = "=IF(OR(C1=""05"",C1=""07"",C1=""10""," & _
"C1=""12"",C1=""03"",C1=""01"",C1=""08""),""31""," & _
"IF(OR(C1=""04"",C1=""06"",C1=""09"",C1=""11""),""30""," & _
"IF(C1=""02"",""29"","""")))"
End Sub

Perhaps a better approach would be


=IF(OR(C1>=1,C1<=12),CHOOSE(C1,31,29,31,30,31,30,31,31,30,31,30,31),"")

or

=IF(OR(C1>=1,C1<=12),DAY(DATE(YEAR(TODAY()),C1+1,0)),"")
 
Back
Top