2017-06-14 26 views
0

早上好,如果我的細胞沒有顏色,然後將其複製

我有一個C8範圍:C17 一些細胞是紅色,而一些沒有顏色。 我想要的細胞無顏色轉移到A列

這是我的代碼:

Dim a As Long 
    a = 1 'we set the row where we start filling in the single sames 
    If Range("C8:C17").Interior.ColorIndex = xlColorIndexNone Then 
     Cells(a, "A").Value = Range("C8:C17").Value 
     a = a + 1 
    End If 

回答

4

下面的代碼通過Range("C8:C17")所有細胞循環,如果當前單元格不着色檢查。如果它不是colores,則將它粘貼到下一個空行(從第一行開始)的A列。

Option Explicit 

Sub CopyColCells() 

Dim a As Long 
Dim C As Range 

a = 1 'we set the row where we start filling in the single sames 
For Each C In Range("C8:C17") 
    If C.Interior.ColorIndex = xlColorIndexNone Then 
     Cells(a, "A").Value = C.Value 
     a = a + 1 
    End If 
Next C 

End Sub 
+0

它的工作原理!我在新專欄中遇到了一個問題,謝謝! – babou

+2

@babou your'e歡迎:)隨時標記爲「答案」 –