使用VBA和Excel 我有一个动态范围,我想应用基本的条件格式,如果数字大于0.8,则将框变成绿色
某些单元格包含文本而不是数字,我不想格式化这些单元格。
这是我到目前为止所拥有的,但是没有用。
With RESPXL.xlsWS4.Range(RESPXL.xlsWS4.Cells(2, 7), RESPXL.xlsWS4.Cells(RECCNT, 19)).FormatConditions.Add(xlCellValue, xlGreater, "=IsNumber(xlCellValue)", "=0.8")
.Font.Bold = True
.Font.Color = -11489280
.StopIfTrue = False
.Interior.Color = 13421823
.Interior.ThemeColor = xlThemeColorAccent6
.Interior.TintAndShade = 0.799981688894314
End With
答案 0 :(得分:1)
您应该使用公式来确定您的情况,
.FormatConditions.Add Type:=xlExpression, Formula1:="=AND($A1>0.8, ISNUMBER($A1))"
答案 1 :(得分:1)
使用命名范围“ RngTest”,以下操作即可完成
Sub CFTest()
Dim Cond1 As FormatCondition
Dim CFRange As Range: Set CFRange = Range("RngTest")
Dim FirstCell As String: FirstCell = Replace(CFRange(1).Address, "$", "")
With CFRange
.FormatConditions.Delete
Set Cond1 = .FormatConditions.Add(Type:=xlExpression, Formula1:="=AND(ISNUMBER(" & FirstCell & ")," & FirstCell & ">0.8)")
End With
With Cond1
.Font.Bold = True
.Font.Color = -11489280
.StopIfTrue = False
.Interior.Color = 13421823
.Interior.ThemeColor = xlThemeColorAccent6
.Interior.TintAndShade = 0.799981688894314
End With
End Sub