I'm trying to write a code which changes the color of cells in the specified area based on previously defined values (dates). So if the defined date minus actual date is smaller than zero then cells interior color changes to red.
I'm pulling data from area: From row 2 To 160 And column 24 to 33. I'm checking the difference between these dates and the actual date and if its less than zero I want cells in the region: Row 2 To 160 and column 10 to 19 to change color to red.
I wrote a simple code to only test if it works. But the color is changed to red skipping the condition (some values are grater then zero and either way they are red).
Sub niowy()
Worksheets("External").Activate
For i = 2 To 160
For j = 24 To 33
For k = 10 To 19
If Cells(i, j).Value = "" Then
Cells(i, j).Select
Cells(i, k).Select
ElseIf Cells(i, j).Value - Date > 0 And Cells(i, j).Value - Date < 20 Then
Cells(i, k).Interior.Color = rgbOrange
ElseIf Cells(i, j).Value - Date < 0 Then
Cells(i, k).Interior.Color = rgbRed
End If
Next k
Next j
Next i
End Sub
If you have any idea to speed up a code a little bit or a different approach I would be grateful for any ideas. Take into consideration I'm just starting learning vba so the code might be pretty messy. I also tested "datediff" function but it failed.