Forum Discussion
Show feb 29th in leap years
Hi, I have a series of numbers (B6 till B36) containing numbers 1 till 31 for the days of the month. The last cell is dependent on cell M2 containing the word "januari, march, may...etc" for showing 31 or staying empty. Cell B34 contains a simulair formula for M2 containing the word "februari". Works perfectly....
Exept for leap years. Years are located in K2.
How can I built a formula containing this:
if M2 is not "februari";29 unless K2 contains "2020", "2024", "2028", "2032", "2036" or "2040" (20 years in the future should be sufficiant)
Thanks for the help!!
Erwin
If I understood you correctly your data is like this
In B6 you may use
=IF((MONTH(DATE($K$2,MONTH(1&LEFT($M$2,3)),ROW()-ROW($B$5)))=MONTH(1&LEFT($M$2,3))),ROW()-ROW($B$5),"")
and drag it down till B36. It works for any correct combination of year and month in K2 and M2 and skips 29, 30, 31 if there are no such days in year and month.
7 Replies
- SergeiBaklanDiamond Contributor
I didn't catch exactly how your cells linked by formulas, but you may check if the year leap or not by
=IF(DAY(DATE(G2,2,29))=1,"Not leap","Leap")
thus something like
=IF(DAY(DATE(G2,2,29))=1,"","Feb 29")
- EbbulkCopper Contributor
SergeiBaklan Thanks for the response.
You're thinking the other way around. I'm not trying to determine if the year is a leap year, but I'm trying to show or hide the number 29 (in cell B34) depending on both the month (cell M2) and year/leap year (Cell K2)
The code I have now is: =IF(NOT(M2="februari");29;"")
wich hides the 29 (and 30, 31 in B35 and B36) depending on the name of the month. The formula i'm trying to built now is like this:
=IF(NOT(M2="februari");29;"") UNLESS K2= 2020, 2024, 2028, 2032, 2036 or 2040- SergeiBaklanDiamond Contributor
If I understood you correctly your data is like this
In B6 you may use
=IF((MONTH(DATE($K$2,MONTH(1&LEFT($M$2,3)),ROW()-ROW($B$5)))=MONTH(1&LEFT($M$2,3))),ROW()-ROW($B$5),"")
and drag it down till B36. It works for any correct combination of year and month in K2 and M2 and skips 29, 30, 31 if there are no such days in year and month.