两个柱子的条件形成

时间:2016-07-28 18:55:56

标签: excel-vba vba excel

如何让两列满足这两个条件,然后将其突出显示为红色?现在要么是列符合条件,那么它会突出显示红色。

         If InStr(rcol.Value, "L-Start") > 0 Then
                        With rcol.EntireColumn.Cells
                        .FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="=(today() - 120)"
                        With .FormatConditions(1).Font
                            .Color = RGB(255, 0, 0)
                        End With
                    End With
                    End If

                If InStr(rcol.Value, "L-Type") > 0 Then
                    With rcol.EntireColumn.Cells
                        .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Q"""

                        With .FormatConditions(1).Font
                            .Color = RGB(255, 0, 0)
                        End With
                    End With
                End If

1 个答案:

答案 0 :(得分:0)

如果满足两个条件,此代码将仅将单元格绘制为红色

            If InStr(rcol.Value, "L-Start") > 0 And InStr(rcol.Value, "L-Type") > 0 Then
                With rcol.EntireColumn.Cells
                    .FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="=(today() - 120)"
                    .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Q"""
                    With .FormatConditions(1).Font
                        .Color = RGB(255, 0, 0)
                    End With
                    With .FormatConditions(2).Font
                        .Color = RGB(255, 0, 0)
                    End With
                End With
            End If

我希望这是你需要的。