Your code didn't quite work but I removed all the excess and it is working kinda again. I get an error "Object Variable or with block variable not set" and that highlights the rownum = rRange.row. I think it has something to do with how my range for each month is set up Mrng variable.
The code doesn't error out until after about 6 cells have been shaded.
Code:
Dim rRange as Object
Dim rownum as Long
Dim Mrng as Object
Dim i as Integer
Dim initDate as Date
Do While rsLeave.EOF = False
initDate = rsLeave![Start Date]
' rownum = rownum + 1
' rownum = xlApp.xlSh.WorksheetFunction.Row(rsLeave![DoD ID])
' Set rRange = xlSh.Cells.Find(What:=rsLeave![DoD ID], After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
Set rRange = xlSh.cells.Find(What:=rsLeave![DoD ID])
rownum = rRange.Row
i = DateDiff("d", rsLeave![Start Date], rsLeave![End Date])
If Month(initDate) = 1 Then
Set Mrng = xlSh.Range("CR4", "DV210")
ElseIf Month(initDate) = 2 Then
Set Mrng = xlSh.Range("DW4", "EX210")
ElseIf Month(initDate) = 3 Then
Set Mrng = xlSh.Range("EY4", "GC210")
ElseIf Month(initDate) = 4 Then
Set Mrng = xlSh.Range("GD4", "HG210")
ElseIf Month(initDate) = 5 Then
Set Mrng = xlSh.Range("HH4", "IL210")
ElseIf Month(initDate) = 6 Then
Set Mrng = xlSh.Range("IM4", "JP210")
ElseIf Month(initDate) = 7 Then
Set Mrng = xlSh.Range("JQ4", "KU210")
ElseIf Month(initDate) = 8 Then
Set Mrng = xlSh.Range("KV4", "LZ210")
ElseIf Month(initDate) = 9 Then
Set Mrng = xlSh.Range("MA4", "ND210")
ElseIf Month(initDate) = 10 Then
Set Mrng = xlSh.Range("D4", "AH210")
ElseIf Month(initDate) = 11 Then
Set Mrng = xlSh.Range("AI4", "BL210")
ElseIf Month(initDate) = 12 Then
Set Mrng = xlSh.Range("BM4", "CQ210")
End If
With Mrng
xlSh.cells(rownum, Day(initDate + i)).Interior.ColorIndex = 4
End With
rsLeave.MoveNext
Loop
rsLeave.Close
The code doesn't error out until after about 6 cells have been shaded.