Project a date of completion

DoctorAwe

New Member
Joined
Oct 16, 2012
Messages
14
This code projects a date that $0 will occur if I start spending daily values from an amount. An example would be if I start on October 17th with $200 and spend $10 each weekday and $5 each Saturday following then the return is December 12th.

I would like to add a list to the sheet, of individual dates that should be considered as $0 spent.

For example, if December 3rd 2012 was in the list then the code would return December 13th.

Code:
Public Function udfDepDate2(startDollars, wdDollars, satDollars, parmDate, parmDateType)'parmDateType should be "START" or "END"
'Custom calculate value to zero
'This goes in a Module [Alt+F11 Alt+I & M]
'For example, A1=$200 (total money), B1=$10 (weekday dollars spent), C1=$5 (Saturday dollars spent), D1= October 16, 2012 (Start date of spending), E1=**End date** (day when $0 occurs)?
Const sunDollars = 0
Const doDebug = True


Dim curDate As Date
Dim curVal As Long, depVal As Integer
Dim vStep As Integer


udfDepDate2 = "#N/A"
vStep = 100


If Not IsDate(parmDate) Then GoTo ExitOther
If Not IsNumeric(startDollars) Then GoTo ExitOther
If Not IsNumeric(wdDollars) Then GoTo ExitOther
If Not IsNumeric(satDollars) Then GoTo ExitOther
If UCase(parmDateType) = "START" Then vStep = 1
If UCase(parmDateType) = "END" Then vStep = -1
If vStep > 1 Then GoTo ExitOther


curDate = parmDate
curVal = startDollars


Do While curVal > 0
    Select Case Weekday(curDate)
        Case Is = 1
            depVal = sunDollars
            curVal = curVal - depVal
        Case Is = 7
            depVal = satDollars
            curVal = curVal - depVal
        Case Else
            depVal = wdDollars
            curVal = curVal - depVal
    End Select
    
    If doDebug Then Debug.Print Format(curDate, "ddd-mm/dd"), depVal, curVal
    
    'Escape on the day the $ are depleted
    If curVal <= 0 Then Exit Do
    
    curDate = curDate + vStep
    
    DoEvents
Loop


ExitNormal:
    udfDepDate2 = curDate
    Exit Function


ExitOther:
    udfDepDate2 = "#N/A"


End Function
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
An example would be if I start on October 17th with $200 and spend $10 each weekday and $5 each Saturday following then the return is December 12th.
?!?!
For example, if December 3rd 2012 was in the list then the code would return December 13th.
?!?!
Excel Workbook
ABCDE
1Start $weekday spendSat spendStart DateCompletion date
2 200.00 10.00 5.0016-Oct-1209-Nov-12
303-Dec-1227-Dec-12
417-Oct-1210-Nov-12
Sheet
 
Upvote 0
Sorry about the mistakes.

Example should be: if start on **November** 17th , then will end on December 12th.


ABCDEF
1Start $Weekday SpendSat SpendChoose to
Start or End
on Date given
Date GivenDate Returned
2200105START17-Nov-201212-Dec-2012
3200105END17-Nov-201224-Oct-2012

<tbody>
</tbody>


F2 =udfDepdate2( A2,B2,C2,E2,D2)
F3 =udfDepdate2( A3,B3,C3,E3,D3)


Here is what I would like to add:

G
1Dates to consider $0
21-Dec-2012
31-Nov-2012
etc.

<tbody>
</tbody>

The entire list of dates would be considered by all of the calculations, not just the one occurring on that row.
 
Last edited:
Upvote 0
Here is what I would like to add:

G
1Dates to consider $0
21-Dec-2012
31-Nov-2012
etc.

<tbody>
</tbody>

The entire list of dates would be considered by all of the calculations, not just the one occurring on that row.
I'm not at all sure what you want:
What do you want to do with these dates to consider 0$? Where do you want to see results?
 
Upvote 0
Sure.

I hope this similar situation will help make sense of what I'm asking.

Consider the expenditure like wages for days worked. The person working for me would earn, $10 on week days, $5 on Saturdays, and the person doesn't work Sundays or public holidays (both $0). I would like to add a list of "public holiday" dates.

I am calculating the date I will run out of money if I start with $200 to pay the wages. But it is not accurate because it does not consider public holidays.


I would like the results to be in the Date Returned column in place of the current results.
 
Last edited:
Upvote 0
This needs a change to the udf. Here it is with the changes made in red (if I remember them right):
Code:
Public Function udfDepDate2(startDollars, wdDollars, satDollars, parmDate, parmDateType[COLOR=#ff0000], TheHolidays[/COLOR])    'parmDateType should be "START" or "END"
'Custom calculate value to zero
'This goes in a Module [Alt+F11 Alt+I & M]
'For example, A1=$200 (total money), B1=$10 (weekday dollars spent), C1=$5 (Saturday dollars spent), D1= October 16, 2012 (Start date of spending), E1=**End date** (day when $0 occurs)?
Const sunDollars = 0
Const doDebug = False    'True
Dim curDate As Date
Dim curVal As Long, depVal As Integer
Dim vStep As Integer
udfDepDate2 = "#N/A"
vStep = 100
If Not IsDate(parmDate) Then GoTo ExitOther
If Not IsNumeric(startDollars) Then GoTo ExitOther
If Not IsNumeric(wdDollars) Then GoTo ExitOther
If Not IsNumeric(satDollars) Then GoTo ExitOther
If UCase(parmDateType) = "START" Then vStep = 1
If UCase(parmDateType) = "END" Then vStep = -1
If vStep > 1 Then GoTo ExitOther


curDate = parmDate
curVal = startDollars
[COLOR=#ff0000]Hols = TheHolidays.Value[/COLOR]

Do While curVal > 0
    'is date in the TheHolidays range? (gave up fighting with .Find to look for dates!):
    [COLOR=#ff0000]IsAHoliday = False
    For Each dte In Hols
        If dte = curDate Then
            IsAHoliday = True
            Exit For
        End If
    Next dte

    If Not IsAHoliday Then[/COLOR]
        Select Case Weekday(curDate)
            Case Is = 1
                depVal = sunDollars
                curVal = curVal - depVal
            Case Is = 7
                depVal = satDollars
                curVal = curVal - depVal
            Case Else
                depVal = wdDollars
                curVal = curVal - depVal
        End Select
  [COLOR=#ff0000]  End If[/COLOR]

    If doDebug Then Debug.Print Format(curDate, "ddd-mm/dd"), depVal, curVal
    'Escape on the day the $ are depleted
    If curVal <= 0 Then Exit Do

    curDate = curDate + vStep

    DoEvents
Loop
ExitNormal:
udfDepDate2 = curDate
Exit Function
ExitOther:
udfDepDate2 = "#N/A"
End Function
The screenshot and formulae:
Excel Workbook
ABCDEFGH
1Start $weekday spendSat spendChoose toStart or Endon Date givenStart DateCompletion dateDates to consider $0
2 200.00 10.00 5.00Start17-Nov-1214-Dec-12Sat 01-Dec-12
3 200.00 10.00 5.00End17-Nov-1224-Oct-12Mon 19-Nov-12
4 200.00 10.00 5.00Start17-Nov-1214-Dec-12
Sheet
 
Upvote 0
Thank you very much p45cal!
That is exactly what I want.

Thank you again for putting up with my unclear requests!
 
Upvote 0

Forum statistics

Threads
1,215,545
Messages
6,125,455
Members
449,228
Latest member
moaz_cma

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