2013-10-19 200 views
0

我有一個巨大的數據格式化爲條件格式,但只有10%的單元格是通過條件格式着色的,所以我只想將彩色單元格的顏色複製到複製範圍跳過將條件格式化顏色從一個範圍複製到另一個範圍的白色VBA Excel

這是將條件格式顏色從範圍複製到範圍的代碼。我想知道如何跳過白色不被複制,這樣我就可以減少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 

感謝

回答

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 
+0

優秀..謝謝 –

相關問題