VBA:删除打印区域外的条件格式

问题描述 投票:0回答:1

我有很多带有复杂条件格式的工作表 - 我想自动化一种方法来清除打印区域之外的所有条件格式。有谁知道该怎么做吗?

在其他论坛中,我只看到从整个工作表而不是选定范围清除条件格式的解决方案。我的目标是自动复制另一个表格下方其他工作表中的表格,而不对目标工作表进行条件格式设置。手动修改条件格式的范围的工作量太大。 谢谢!

excel vba formatting copy-paste conditional-formatting
1个回答
0
投票
  • 下面的代码清除目标工作表上的条件格式。
Option Explicit
Sub Demo()
    Dim srcRng As Range, desRng As Range, oCF As FormatCondition
    Set srcRng = Sheets("Sheet1").Range("B3:F10") ' source table, modify as need
    Set desRng = Sheets("Sheet2").Range("D5") ' destination top-left cell
    With desRng.Resize(srcRng.Rows.Count, srcRng.Columns.Count)
        For Each oCF In .FormatConditions
            oCF.Delete
        Next
    End With
    srcRng.Copy desRng
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.