Reputation: 1509
I need to compare one cell with next and if next is greater more than 3 than first, than to make it's color. example: 1 2 6 3 2 8
1 compare with 2 = do not do nothing
2 compare with 6 = make it's color
6 compare with 3 = make it's color to
3 compare with 2 = do not do nothing
2 compare with 8 = make it's color.
Here is code that make cells less then 4 color, but I can't understand how to diff one cell with next :(
Sub Color()
Dim i As Integer
For i = 1 To 7
With ActiveSheet.Cells(i)
If .Value < 4 Then
.Interior.Color = QBColor(10)
End If
End With
Next i
End Sub
Upd:
Oh! Look like I have found solution!
Sub Color()
Dim i As Integer
For i = 1 To 7
With ActiveSheet.Cells(i)
If ActiveSheet.Cells(i) < ActiveSheet.Cells(i + 1) Then
ActiveSheet.Cells(i + 1).Interior.Color = QBColor(10)
End If
End With
Next i
End Sub
Upvotes: 0
Views: 131
Reputation: 55692
You could use conditional formatting for this rather than VBA, Debra covers this topic thoroughly here, http://www.contextures.com/xlcondFormat01.html
In your case:
screenshot from xl2010 below
Upvotes: 2