Vogel612
Vogel612

Reputation: 5647

Cannot Call FormatConditions.Add with type

I'm running a quite simple FormatConditions adding programmatically...

someVar has the value 168. This code fails on the .FormatCondtions.Add line

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

I have also tried to use Selection, the Error stays the same

Workbooks(1).Worksheets(1).Range("C2:C" & someVar).Select
With Selection
   'See above
End With

Upvotes: 1

Views: 333

Answers (1)

Dmitry Pavliv
Dmitry Pavliv

Reputation: 35853

Try this one:

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

Upvotes: 2

Related Questions