我有一个包含许多重复的条件格式实例的工作表。 我正在尝试编写代码来整理/删除其中的许多代码。
我需要修改格式条件。 知道为什么以下不起作用吗?
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