Marcus, try this.
BTW, I've seen lots of mikerickson's posts, and commend his advice.
Sub DateCalc()
' (1) Establish the range of the loop (G2 to last non-blank row)
' (2) based on value in column G (Label = CType = Schedule Type or _
' sSchedType) and date in column M (Label = CUSTFLD6 = Last _
' Service Date or datNextSvc), calculate the next scheduled _
' service date;
' (3) compare value in Calculated Service Date to value in Column N _
' (Label = CUSTFLD7 = Next Scheduled Service or datNextSvc;
' (4) if Column N is not blank and the value >= to today, Scheduled _
' Service Date = Column N value, else Next Scheduled Service _
' Date = Calculated Next Scheduled Service Date,
' (5) enter the calculated value to column T of that row
Dim datLastSvc As Date
Dim datNextSvc As Date
Dim rngCell As Range
Dim iMon As Integer
iMon = Month(Date)
For Each rngCell In Range("G2", Range("G65536").End(xlUp))
datLastSvc = Cells(rngCell.Row, "M").Value
If IsDate(Cells(rngCell.Row, "N").Value) Then
datNextSvc = Cells(rngCell.Row, "N").Value
Else
datNextSvc = DateValue("1/1/1900")
End If
If datNextSvc <= Date Then
Select Case rngCell.Value
Case "W"
datNextSvc = datLastSvc + 7
Case "EOW"
datNextSvc = datLastSvc + 14
Case "EOWTh" ' every other week on Thursday
datNextSvc = datLastSvc + 14
' adjust to Thursday
datNextSvc = datNextSvc + 5 - Weekday(datNextSvc)
Case "2xMo"
datNextSvc = datLastSvc + 15
Case "EOWS1xMoW"
If iMon >= 5 And iMon <= 10 Then
datNextSvc = datLastSvc + 14
Else
datNextSvc = datLastSvc + 30
End If
Case "ETW" ' every third week
datNextSvc = datLastSvc + 21
Case "15xYr"
If iMon >= 5 And iMon <= 10 Then
datNextSvc = datLastSvc + 21
Else
datNextSvc = datLastSvc + 30
End If
Case "1xMo"
datNextSvc = datLastSvc + 30
Case "EOM"
datNextSvc = datLastSvc + 60
Case "OnCall"
' dunno ...
Case "Q"
datNextSvc = datLastSvc + 90
Case Else
rngCell.Select
MsgBox "Schedule type??", vbCritical
Exit Sub
End Select
End If
Next rngCell
Cells(rngCell.Row, "T") = datNextSvc
End Sub
Bookmarks