ModifyAppliesToRange不起作用

我有一个工作表与许多重复的条件格式实例。 我试图编写代码来整理/删除其中的很多。

我需要修改格式条件。 任何想法为什么以下不起作用?

Sub UpdateCondition(ByRef bFirst As Boolean, rng As Range, f As FormatCondition, replacementFormula As String) If bFirst Then f.Modify f.Type, , replacementFormula f.ModifyAppliesToRange rng bFirst = False Else f.Delete End If End Sub 

我得到以下错误:

对象'FormatCondition'的方法'ModifyAppliesToRange'失败

此代码适用于我的许多条件。 只有其中一些绊倒。

– 编辑 –

我的通话代码如下

 Dim f As FormatCondition Dim bFirst As Boolean Dim i As Integer Set rng = SomeRangeOnTheSheet bFirst = True For i = ActiveSheet.Range(Cells.Address).FormatConditions.Count To 1 Step -1 Set f = ws.Range(Cells.Address).FormatConditions(i) If f.Formula1 = "..Some Formula.." Then UpdateCondition bFirst, rng, f, replacementFormula End If Next 

– 编辑 –

 Function SomeRangeOnTheSheet() As Range Dim cell1 As Range Dim cell2 As Range Set cell1 = Cells(Range("Roster").row, Range("StartDate").Column) Set cell2 = Cells(Range("Roster").row + Range("Roster").Rows.Count - 1, Range("Roster").Column + Range("Roster").Columns.Count - 1) Set RosterDataRange = Range(cell1, cell2) End Function