|
- Sub Test2()
- Dim lngRows As Long
- Dim arr As Variant, dblVal As Double
- Dim dblRedMax As Double, dblRedMin As Double, dblYelMax As Double, dblYelMin As Double
- Dim varFontColor As Variant, varBackColor As Variant
-
- lngRows = Sheet1.Range("D" & Rows.Count).End(xlUp).Row
- arr = Sheet1.Range("D4:M" & lngRows)
-
- For lngRows = LBound(arr) To UBound(arr)
- dblRedMax = arr(lngRows, 3)
- dblYelMax = arr(lngRows, 4)
- dblYelMin = arr(lngRows, 5)
- dblRedMin = arr(lngRows, 6)
-
- dblVal = arr(lngRows, 1)
-
- Select Case dblVal
- Case Is > dblRedMax '大于红上
- varBackColor = vbRed
- varFontColor = vbWhite
- Case Is >= dblYelMax '大于等于黄上,小于等于红上
- varBackColor = vbYellow
- varFontColor = vbBlack
- Case Is >= dblYelMin '大于等于黄下,小于黄上
- varBackColor = vbGreen
- varFontColor = vbWhite
- Case Is >= dblRedMin '大于等于红下,小于黄下
- varBackColor = vbYellow
- varFontColor = vbBlack
- Case Is < dblRedMin '小于红下
- varBackColor = vbRed
- varFontColor = vbWhite
- End Select
-
- With Sheet1.Range("D" & lngRows + 3)
- .Font.Color = varFontColor
- .Interior.Color = varBackColor
- End With
- Next
-
- End Sub
复制代码 |
|