jeffmoseler
Well-known Member
- Joined
- Jul 16, 2004
- Messages
- 540
I have the following code to adjust the color of a tab if certain conditions are present.
Everytime it runs is errors on this line:
Saying:
"Application-defined or object-defined error"
I call it when there is a change on the sheet and when the worksheet opens. And it seems to be completely random. Sometimes it causes an error and sometimes it runs fine. Any thoughts?
Code:
Public Sub CheckForTabColorSuspects1019()
Dim i, vk As Long
Sheets("Suspects 10 - 19").Tab.ColorIndex = xlColorIndexNone
vk = Application.WorksheetFunction.CountA(Range("A12:A1000"))
If vk = 0 Or vk = Empty Then
Exit Sub
End If
vk = vk + 11
i = Sheets("Suspects 10 - 19").Range("A11:AZ11").Find("Added", Range("A11"), xlFormulas, xlWhole, xlByColumns, xlNext).Column
i2 = Sheets("Suspects 10 - 19").Range("A11:AZ11").Find("App?", Range("A11"), xlFormulas, xlWhole, xlByColumns, xlNext).Column
Dim rng As Range
Dim vMaxDate As Date
For j = 12 To vk
Set rng = Sheets("Suspects 10 - 19").Range(Cells(j, i), Cells(j, i2))
vMaxDate = Application.WorksheetFunction.Max(rng)
If vMaxDate <= Date - 14 Then
Sheets("Suspects 10 - 19").Tab.ColorIndex = 3
Exit Sub
End If
If vMaxDate <= Date - 7 Then
Sheets("Suspects 10 - 19").Tab.ColorIndex = 6
End If
Next j
End Sub
Everytime it runs is errors on this line:
Code:
Set rng = Sheets("Suspects 10 - 19").Range(Cells(j, i), Cells(j, i2))
Saying:
"Application-defined or object-defined error"
I call it when there is a change on the sheet and when the worksheet opens. And it seems to be completely random. Sometimes it causes an error and sometimes it runs fine. Any thoughts?