我需要将一个单元格与下一个单元格进行比较,如果下一个单元格比第一个单元格大于3,则需要将其与颜色进行比较。 例如: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.
这是使细胞少于4色的代码,但我无法理解如何用下一个细胞区分一个细胞:(
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:
哦!看起来我找到了解决方案!
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
答案 0 :(得分:2)
您可以使用条件格式而不是VBA,Debra在此详细介绍了此主题,http://www.contextures.com/xlcondFormat01.html
在你的情况下:
下面的xl2010截图