0
我在excel-vba有一個問題,我想一個單元格的顏色複製到下一但當它拷貝,顏色始終是白色或「無填充」。 下面的代碼示例是問題所在區域:應用主題顏色透視表相鄰小區
'If the status cell('E') is empty (is not a table header)
If rngCell.Offset(0, 2).Value = "" Then
'Apply the color of 'C' column to the cells in the status('E') and note('F') column
rngCell.Offset(0, 2).Interior.ThemeColor = rngCell.Interior.ThemeColor
rngCell.Offset(0, 3).Interior.ThemeColor = rngCell.Interior.ThemeColor
End If
我相信問題是,我試圖複製在數據透視表,是不是在數據透視表的單元格的單元格的顏色。這就是我使用'.mecolor'的原因顏色被設置爲「樣式樞軸培養基2」,用.ColorIndex顏色是不可用的。
我一直在使用.ColorIndex,。顏色,.ThemeColor嘗試,但所有的嘗試都給予同樣的結果
下面的代碼示例是整個代碼給上下文,但是在最後else語句的問題奠定。
'Initialize variables to save cell ranges
Dim rngTables As range
Dim rngClick As range
Dim rngCell As range
'Set the range of cells to be checked
'We want to check the description fields to check if there is description text
'Cells with descriptions are the parameters being tested
Set rngTables = range("C4:C200")
'Loop through the cells in rngTables using rngCell to check each cell individually
For Each rngCell In rngTables
'Add cells to rngClick if they are NOT Blank
If Not rngCell.Value = "" And Not rngCell.Value = "Description" Then
If Not rngClick Is Nothing Then
'Add the 2nd, 3rd, 4th... Cell to our new range, rng2
'This is the most common outcome so place it first in the IF test (faster coding)
Set rngClick = Union(rngClick, rngCell.Offset(0, 2))
Else
'The first valid cell becomes rngClick
Set rngClick = rngCell.Offset(0, 2)
End If
Else
'If the status cell('E') is empty (is not a table header)
If rngCell.Offset(0, 2).Value = "" Then
'Apply the color of 'C' column to the cells in the status('E') and note('F') column
rngCell.Offset(0, 2).Interior.ThemeColor = rngCell.Interior.ThemeColor
rngCell.Offset(0, 3).Interior.ThemeColor = rngCell.Interior.ThemeColor
End If
End If
Next rngCell