date calculator

C.S.

Board Regular
Joined
Nov 20, 2008
Messages
89
Hi,

I'm building a calculator of sorts for dates. I have a start date in A1. Next to the start date I have a list:

10 days from -start date- is:
15 days from -start date- is:
20 days from -start date- is:
and so on...

I need a formula to return a date that is however many days specified from the start date. If that date lands on a sat or sun I need it to return me the date for the monday after. For example, if my start date is 10/15/09 (thursday) and 10 days from that is 10/25/09 (sunday) I need it to return the date of 10/26/09 (monday). I also need it exclude a range of holidays i have listed.

Thanks,
c.s.
 

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).
thanks for the suggestion you linked except that one excludes saturdays and sundays, i need it to include them in the count, but, if the end date lands on a saturday or sunday, then I need it to give me the date of the monday after that weekend.

cs
 
Upvote 0
Oh yeah, I guess it's not the same... How about this, does it return the expected results?

Excel Workbook
ABCD
1StartDaysEndHolidays
210/22/20091011/3/20092-Nov
310/22/20091511/6/2009
410/22/20092011/11/2009
1
Excel 2000
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}. Note: Do not try and enter these manually yourself
...D2:D10 is the holidays list.
[/B]
 
Last edited:
Upvote 0
Works great! One more thing, how would the formula need to be adjusted if I wanted the date to move to the friday before as opposed to the monday after (provided the end date lands on a sat or sun)?

Thanks, you've been a tremendous help!

cs
 
Upvote 0
I've noticed something else I hope you can help with. It seems as if the formula will take into account for the holidays by not allowing a date to land on it, however, it doesn't seem to exclude them from the day count. For instance, if my start date is 1/12/09 and there is 10 days I want it to calculate out to, it should return me a date of 1/23/09 due to the 19th being a holiday. As it is, it is giving me a date of 1/22/09. Thanks again for all your help, I hope this makes sense.

cs
 
Upvote 0
I think the following UDF would meet your requirements...
Excel Workbook
ABCD
1Start DateDays to AddHoliday RangeEnd Date
212/01/20091019/01/200925/01/2009
320/01/2009
421/01/2009
???
Excel 2003
Cell Formulas
RangeFormula
D2=GetDate(A2,B2,$C$2:$C$4)



Code:
Function GetDate(StartDate As Date, AddDays As Long, Optional HolidayRange As Range) As Date
    Dim Rng As Range
    Dim Count As Long
    Dim NewDate As Date
    Application.Volatile
    NewDate = StartDate + AddDays
    Select Case Weekday(NewDate)
    Case 7
        NewDate = NewDate + 2
    Case 1
        NewDate = NewDate + 1
    End Select
    If Not HolidayRange Is Nothing Then
        For Each Rng In HolidayRange.Cells
            If (CLng(Rng.Value)<= CLng(NewDate)) And (CLng(Rng.Value) >= CLng(StartDate)) Then
                NewDate = NewDate + 1
            End If
        Next Rng
    End If
    GetDate = NewDate
End Function
 
Upvote 0
sandeep,

thanks so much for your response, except the problem is I have no idea how to use your suggestions. I apologize for being inept, but could you give me a little step by step process outline? I have no experience whatsoever with code or macros.

THanks again,
cs
 
Upvote 0
sandeep,

thanks so much for your response, except the problem is I have no idea how to use your suggestions. I apologize for being inept, but could you give me a little step by step process outline? I have no experience whatsoever with code or macros.

THanks again,
cs

You will need to paste the code in the Visual Basic Editor (VBE).

In your Excel window press Alt+F11 for the VBE to open up. Then, on the menu bar at the top, go to Insert | Module. Paste the code from my earlier post in the white area that appears on the right.

Close the VBE.

You can use this function as a normal worksheet function. It has the format...

=GetDate(StartDate, AddDays, HolidayRange)

StartDate accepts a date as an input, AddDays accepts an integer as input, HolidayRange is a range that contains your holiday dates. HolidayRange is optional i.e. the code will work even without input for this field.

In the example in my earlier post, the StartDate is in A2, B2 contains the number of days to be added and C2:C4 contains the HolidayRange.

Also, you can remove the line: Dim Count as Long from the code as it is not required.

Hope this helps.
 
Last edited:
Upvote 0
sandeep,

thanks for the directions it was a piece of cake, except I need the function to adjust the target date, if it lands on a sat or sun, to the friday before the weekend, instead of after.

thanks,
cs
 
Upvote 0

Forum statistics

Threads
1,223,959
Messages
6,175,647
Members
452,663
Latest member
MEMEH

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