2016-07-28 43 views
0

如何使两列满足两个条件然后将其突出显示为红色?现在是列满足条件,然后它会突出显示红色。两个柱子的条件形成

  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 
+0

使用AND检查同一IF中的两个条件:如果InStr(rcol.Value,“L-Start”)> 0并且InStr(rcol.Value,“L-Type”)> 0 Then'。它不仅仅是突出显示红色,所以我无法帮助更多,因为它很难解释。 –

+0

你是否只想突出显示列,如果两者都是真的? – Luke

回答

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 

我希望这是你所需要的。