Reputation: 1
I am trying to write a program that loops through every row in each table (one table per sheet) in order to color code it, similar to conditional formatting. This doesn't move on to the next sheet, so it only color codes the sheet I have open. I would like it to move on the the next automatically. Any input is appreciated.
Dim ccShipDate As Variant
Dim ccRow As Integer
Dim wsht As Worksheet
ccRow = 2
ccShipDate = Cells(ccRow, 6)
For Each wsht In Worksheets
If wsht.Name = "ManualReview" Or wsht.Name = "Filter" Or wsht.Name = "MRF" Or wsht.Name = "ModStd" Then
With Worksheets(wsht.Name)
' loops through "Actual Ship Date" column until empty
' past or today = red
' one day away = yellow
' more than one day = green
Do Until IsEmpty(ccShipDate)
If DateDiff("d", Date, ccShipDate) <= 0 Then
Cells(ccRow, 3).Interior.ColorIndex = 3
ElseIf DateDiff("d", Date, ccShipDate) = 1 Then
Cells(ccRow, 3).Interior.ColorIndex = 6
ElseIf DateDiff("d", Date, ccShipDate) > 1 Then
Cells(ccRow, 3).Interior.ColorIndex = 4
End If
ccRow = ccRow + 1
ccShipDate = Cells(ccRow, 6).Value
Loop
End With
End If
Next wsht
End Sub
Upvotes: 0
Views: 79
Reputation: 1104
To give you a full answer to Scott Craner's comment
Dim ccShipDate As Variant
Dim ccRow As Integer
Dim wsht As Worksheet
ccRow = 2
ccShipDate = Cells(ccRow, 6)
For Each wsht In Worksheets
If wsht.Name = "ManualReview" Or wsht.Name = "Filter" Or wsht.Name = "MRF" Or wsht.Name = "ModStd" Then
With Worksheets(wsht.Name)
Do Until IsEmpty(ccShipDate)
If DateDiff("d", Date, ccShipDate) <= 0 Then
.Cells(ccRow, 3).Interior.ColorIndex = 3
ElseIf DateDiff("d", Date, ccShipDate) = 1 Then
.Cells(ccRow, 3).Interior.ColorIndex = 6
ElseIf DateDiff("d", Date, ccShipDate) > 1 Then
.Cells(ccRow, 3).Interior.ColorIndex = 4
End If
ccRow = ccRow + 1
ccShipDate = .Cells(ccRow, 6).Value
Loop
End With
End If
Next wsht
End Sub
I might also suggest change the If Then
statement to...
If InStr(1, wsht.Name, "Manual Review") Or InStr(1, wsht.Name, "Filter") Or InStr(1, wsht.Name, "MRF") Or InStr(1, wsht.Name, "ModStd")
That way it will check to see if the string is within the sheet names
Upvotes: 2