|
- Sub text()
- Dim RgeMax, columnNumberLetter, column_maximum
- RgeMax = Range("a65536").End(xlUp).Row
- column_maximum = Range("zz1").End(xlToLeft).Column
- columnNumberLetter = ColNumToColLetter(Range("zz1").End(xlToLeft).Column)
- Excel.Application.ScreenUpdating = False
- For i = 1 To column_maximum - 1
- '条件一必须是最小值
- i2 = Range("b2:" & columnNumberLetter & "2").Columns(i)
- i3 = Range("b3:" & columnNumberLetter & "3").Columns(i)
- Call FormatG(Range("b4:" & columnNumberLetter & RgeMax).Columns(i), i2, "-16752384", "13561798", xlBetween, True, i3)
- Call FormatG(Range("b4:" & columnNumberLetter & RgeMax).Columns(i), i2, "-16383844", 13551615, xlLess, False, "")
- Call FormatG(Range("b4:" & columnNumberLetter & RgeMax).Columns(i), i3, "-16383844", 13551615, xlGreater, False, "")
- Next
- Excel.Application.ScreenUpdating = True
- [a1].Select
- End Sub
- Function ColNumToColLetter(colNum As Long) As String
- Dim iAlpha As Long
- Dim iRemainder As Long
- iAlpha = Int(colNum / 27)
- iRemainder = colNum - (iAlpha * 26)
- If iAlpha > 0 Then
- ColNumToColLetter = Chr(iAlpha + 64)
- End If
- If iRemainder > 0 Then
- ColNumToColLetter = ColNumToColLetter & Chr(iRemainder + 64)
- End If
- End Function
- Sub FormatG(reg As Range, pdValue1, Font_C As String, Rge_C As String, OperatorV As String, TF As Boolean, pdValue2)
- reg.Select
- If TF = False Then
- Selection.FormatConditions.Add Type:=xlCellValue, Operator:=OperatorV, _
- Formula1:="=" & pdValue1
- Else
- Selection.FormatConditions.Add Type:=xlCellValue, Operator:=OperatorV, _
- Formula1:="=" & pdValue1, Formula2:="=" & pdValue2
- End If
- Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
- With Selection.FormatConditions(1).Font
- .Color = Font_C
- End With
- With Selection.FormatConditions(1).Interior
- .PatternColorIndex = xlAutomatic
- .Color = Rge_C
- End With
- Selection.FormatConditions(1).StopIfTrue = False
- End Sub
复制代码
将之前的代码拼凑了一下 大概是这样 |
|