Just for fun: Christmas Countdown function

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
20,611
Office Version
  1. 365
Platform
  1. Windows
If you don't specify a year, it will use the current one.

Code:
Function Christmas(Optional yr As Long) As Long
If yr = 0 Then yr = year(Now)
yr = yr + 1
If Date > DateSerial(yr, 12, 25) Then yr = yr + 1
Christmas = (DateSerial(yr, 1, 1) - 6) - Date
End Function
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
LOL. Too soon. :laugh:

I think there is an error in your calculation though because on 12/25/14 =Christmas(2014) will return 1...
I think it should be Christmas = (DateSerial(yr,1,1)-7)-Date

In testing it I also added a new optional argument so that you can specify any start date to so you can see how many days old you will be this Christmas ala
=Christmas(2014,DateValue("yourbirthdate"))
:eeek: I totally fell into the Christmas in October trap.


Code:
Function Christmas(Optional yr As Long, Optional fromDate As Date) As Long
    If fromDate = 0 Then fromDate = Date
    If yr = 0 Then yr = Year(fromDate)
    If fromDate > DateSerial(yr, 12, 25) Then yr = yr + 1
    Christmas = (DateSerial(yr, 12, 25)) - fromDate
End Function
 
LOL. Too soon. :laugh:
smiley-laughing024.gif
Well, if we are going to rush the season... A Blinking Christmas Tree
 
I admit, I've already started my shopping. I just can't handle the crowds anymore and frankly, I'd rather be carrying packages in cool, but not icy weather.
 
Too soon, too soon!!!

Spare thought for those of us who are allergic to seasonal good will, merriment, roast turkey, tinsel and blinking christmas trees!!!

With that in mind I have modified Scott's UDF with a view to, perhaps, giving it broader scope......

Code:
Function Christmas(Optional BahHumbug As Boolean, Optional yr As Long) As String

If yr = 0 Then yr = Year(Now)
yr = yr + 1
If Date > DateSerial(yr, 12, 25) Then yr = yr + 1
NumDays = (DateSerial(yr, 1, 1) - 7) - Date
Txt = " days until Christmas!!"


  If BahHumbug = True Then
        Pre = "Oh no...   "
        CDay = "Blinkin'eck, it's a bit slow on the forum today!"
    Else
        Pre = "Whoopeee...   only "
        CDay = "MERRY CHRISTMAS!!"
  End If


 If NumDays > 0 Then
       Christmas = Pre & NumDays & Txt
  Else
      Christmas = CDay
 End If


End Function
 

Forum statistics

Threads
1,223,723
Messages
6,174,121
Members
452,545
Latest member
boybenqn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top