【问题标题】:Skip White color from copying conditional formatting color from one range to another VBA Excel将条件格式颜色从一个范围复制到另一个 VBA Excel 时跳过白色
【发布时间】:2013-10-28 13:49:51
【问题描述】:

我有大量使用条件格式格式化的数据,但只有 10% 的单元格通过条件格式着色,所以我只想将彩色单元格颜色复制到复制的范围

这是一个将条件格式颜色从一个范围复制到另一个范围的代码。我想知道如何从复制中跳过白色,这样我可以将循环时间减少 90%

Sub MatchColors2()
Dim rngTo As Excel.Range
Dim rngFrom As Excel.Range
Dim i As Long
Dim j As Long

Set rngFrom = ActiveSheet.Range("C5:G1000")
Set rngTo = ActiveSheet.Range("I5:M1000")

For i = 1 To rngFrom.Areas.Count
    For j = 1 To rngFrom.Areas(i).Cells.Count
        rngTo.Areas(i).Cells(j).Interior.Color =rngFrom.Areas(i).Cells(j).DisplayFormat.Interior.Color
    Next j
Next i
End Sub

谢谢

【问题讨论】:

    标签: excel loops formatting conditional vba


    【解决方案1】:

    如果您的意思是只想复制已激活条件格式的单元格的颜色,请添加这样的测试

    (顺便说一句,因为您的 rng 只有一个区域,您不需要外循环)

    For j = 1 To rngFrom.Cells.Count
        If rngFrom.Cells(j).DisplayFormat.Interior.Color <> rngFrom.Cells(j).Interior.Color Then
            rngTo.Cells(j).Interior.Color = rngFrom.Cells(j).DisplayFormat.Interior.Color
        End If
    Next j
    

    【讨论】:

      猜你喜欢
      • 2014-04-09
      • 1970-01-01
      • 2018-01-15
      • 2019-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      • 1970-01-01
      相关资源
      最近更新 更多