2011-07-11 190 views
1

我想用預定義的條件格式在Excel中生成某些vells。如果輸入數字1,則應顯示3個未打開符號的綠色圖標。這裏是我的代碼到目前爲止:excel vba條件格式

Sub AddIconCondFormat(cell1 As range, cell2 As range) 

    range(cell1, cell2).Select 
    With Selection 
     .FormatConditions.Delete 
     '.FormatConditions.Add Type:=xlCellValue, Operator:XlEqual, Formula1: 
    End With 

End Sub 

我不知道.FormatConditions的所有必要參數。有人知道他們是否列在某處?

回答

0

使用宏錄製後,我得到這個代碼的工作原理:

Sub AddIconCondFormat(cell1 As range, cell2 As range) 

range(cell1, cell2).Select 
With Selection 
    .FormatConditions.Delete 
    .FormatConditions.AddIconSetCondition 
    .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority 
    With Selection.FormatConditions(1) 
     .ReverseOrder = False 
     .ShowIconOnly = False 
     .IconSet = ActiveWorkbook.IconSets(xl3Symbols2) 
    End With 
    With Selection.FormatConditions(1).IconCriteria(2) 
     .Type = xlConditionValuePercent 
     .Value = 33 
     .Operator = 7 
    End With 
    With Selection.FormatConditions(1).IconCriteria(3) 
     .Type = xlConditionValuePercent 
     .Value = 67 
     .Operator = 7 
    End With 
End With 

End Sub