使用Excel VBA代码基于单元格值创建突出显示行

时间:2018-08-06 11:27:42

标签: excel vba excel-vba

我想使用vba根据单元格值突出显示行,但我做不到,

我已经在其他条件下编写了此代码:

Sub threecf()
Dim rg As Range
Dim cond1 As FormatCondition, cond2 As FormatCondition, cond3 As FormatCondition
Set rg = Range("A2", Range("I2").End(xlDown))

'clear any existing conditional formatting
rg.FormatConditions.Delete

'define the rule for each conditional format
Set cond1 = rg.FormatConditions.Add(xlCellValue, xlEqual, "=""NO""")
Set cond2 = rg.FormatConditions.Add(xlCellValue, xlEqual, "=""YES""")


'define the format applied for each conditional format
With cond1.Interior.Color = vbRed.Font.Color = vbWhite
End With

With cond2.Interior.Color = vbGreen.Font.Color = vbBlack
End With

End Sub

如果单元格$ Bx为“ NO”,我要突出显示所有行。我知道可以用excel来做,但是不使用vb​​a。

0 个答案:

没有答案