【发布时间】:2018-04-21 18:11:56
【问题描述】:
我试图通过为每列应用不同的条件格式来突出显示值。但是,我找不到跳过整个第一行的有效方法,因为它本质上是标题行,不应应用任何突出显示。以下是我对某些列的代码:
'highlight first row white
With y.Sheets(Sh).Range("Y1:Y1").FormatConditions.Add(Type:=xlExpression, Formula1:="=NOT(ISBLANK(Y1))")
.Interior.Color = rgbWhite
With y.Sheets(Sh).Range("Y:Y").FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="Z")
.Interior.Color = rgbWhite
End With
With y.Sheets(Sh).Range("Y:Y").FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="NA")
.Interior.Color = rgbWhite
End With
With y.Sheets(Sh).Range("Y:Y").FormatConditions.Add(Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=" & imput)
.Interior.Color = rgbOrange
End With
End With
'highlight first row white
With y.Sheets(Sh).Range("Z1:Z1").FormatConditions.Add(Type:=xlExpression, Formula1:="=NOT(ISBLANK(Z1))")
.Interior.Color = rgbWhite
End With
With y.Sheets(Sh).Range("Z:Z").FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="Z")
.Interior.Color = rgbWhite
End With
With y.Sheets(Sh).Range("Z:Z").FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="NA")
.Interior.Color = rgbWhite
End With
With y.Sheets(Sh).Range("Z:Z").FormatConditions.Add(Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=" & imput)
.Interior.Color = RGB(255, 153, 0) 'Orange
End With
我几乎必须在每一列中添加第一个with 语句,将第一行涂成白色,以覆盖后面的格式。有没有更有效的方法来保持第一行不填充?
【问题讨论】:
-
将最后一行设置为变量并使用
Range("A2:A" & LastRow)
标签: vba excel conditional-formatting