* | A | B | C | D | E |
Spreadsheet Formulas | ||||
<tbody> </tbody> |
Public Function udfDepDate(startDollars As Range, wdDollars As Range, satDollars As Range, StartDate As Range)
'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
udfDepDate = "#N/A"
If Not IsDate(StartDate) Then GoTo ExitOther
If Not IsNumeric(startDollars) Then GoTo ExitOther
If Not IsNumeric(wdDollars) Then GoTo ExitOther
If Not IsNumeric(satDollars) Then GoTo ExitOther
curDate = StartDate
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
adjustment = sunDollars + satDollars + wdDollars
If doDebug Then Debug.Print Format(curDate, "ddd"), depVal, curVal
curDate = curDate + 1
DoEvents
Loop
ExitNormal:
udfDepDate = curDate
Exit Function
ExitOther:
udfDepDate = "#N/A"
End Function
Public Function udfDepDate(startDollars As Range, wdDollars As Range, satDollars As Range, StartDate As Range)
'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
udfDepDate = "#N/A"
If Not IsDate(StartDate) Then GoTo ExitOther
If Not IsNumeric(startDollars) Then GoTo ExitOther
If Not IsNumeric(wdDollars) Then GoTo ExitOther
If Not IsNumeric(satDollars) Then GoTo ExitOther
curDate = StartDate
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-dd"), depVal, curVal
[COLOR=#0000ff] 'Escape on the day the $ are depleted
If curVal <= 0 Then Exit Do[/COLOR]
curDate = curDate + 1
DoEvents
Loop
ExitNormal:
udfDepDate = curDate
Exit Function
ExitOther:
udfDepDate = "#N/A"
End Function
* | A | B | C | D | E | F |
* | ||||||
* | ||||||
* | ||||||
END | ||||||
START |
Spreadsheet Formulas | ||||||||||||
<tbody> </tbody> |
Public Function udfDepDate[COLOR=#0000cd]2[/COLOR](startDollars, wdDollars, satDollars, parmDate, [COLOR=#0000cd]parmDateType[/COLOR])
[COLOR=#0000cd]'parmDateType should be "START" or "END"[/COLOR]
'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
[COLOR=#0000cd]Dim vStep As Integer[/COLOR]
udfDepDate2 = "#N/A"
[COLOR=#0000cd]vStep = 100[/COLOR]
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
[COLOR=#0000cd]If UCase(parmDateType) = "START" Then vStep = 1
If UCase(parmDateType) = "END" Then vStep = -1
If vStep > 1 Then GoTo ExitOther[/COLOR]
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 + [COLOR=#0000cd]vStep[/COLOR]
DoEvents
Loop
ExitNormal:
udfDepDate2 = curDate
Exit Function
ExitOther:
udfDepDate2 = "#N/A"
End Function