2016-03-16 83 views
1

我需要删除一行单元取决于listobject中的相对列值。 我如何添加一个基于vba中的相对列值的所有行单元格的条件格式? 例如:如果单元格的值= 1,则整个行需要被三振出局vba excel条件格式在listObject

我尝试这样做:

Dim qt As ListObject 
qt = Sheets.ListObjects(1) 
With qt.DataBodyRange 
.FormatConditions.Delete 
.FormatConditions.Add Type:=xlExpression, Formula1:="=[MyColumn]=0" 
.FormatConditions(0).Font.StrikeOut = True 
End With 

回答

1

下使用.DataBodyRange property检索在左上角的地址是用于formuLa。

With Worksheets("Sheet1") 
    With .ListObjects("Table1") 
     With .DataBodyRange 
      .FormatConditions.Delete 
      .FormatConditions.Add Type:=xlExpression, _ 
       Formula1:="=" & .Cells(1, 1).Address(0, 1) & "=1" 
      .FormatConditions(1).Font.Strikethrough = True 
     End With 
    End With 
End With 

注意,FormatConditions对象有一个基于1 ineex和使用Font.Strikethrough属性,而不是Font.StrikeOut的。

+0

完美! 我不好意思,我带着删除线混淆了三振! – ebelair