我正在以编程方式运行一个非常简单的FormatConditions ...
someVar的值为168.此代码在.FormatCondtions.Add
行
Set Sheet = Workbooks(1).Worksheets(1)
With Workbooks(1).Worksheets(1).Range("C2:C" & someVar)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlDuplicate
.FormatConditions(1).Interior.Color = RGB(255, 40, 80)
End With
我也试过使用Selection,错误保持不变
Workbooks(1).Worksheets(1).Range("C2:C" & someVar).Select
With Selection
'See above
End With
答案 0 :(得分:1)
试试这个:
Set Sheet = Workbooks(1).Worksheets(1)
With Sheet.Range("C2:C" & someVar)
.FormatConditions.Delete
.FormatConditions.AddUniqueValues
.FormatConditions(1).DupeUnique = xlDuplicate
.FormatConditions(1).Interior.Color = RGB(255, 40, 80)
End With