我想将一系列单元格设置为灰色内部。我想要的灰色是在托盘上的黑色和白色之后(顶行,左起第三个)。
我手动将单元格的内部设置为此颜色,然后将vba用于MsgBox ColourIndex。它提出了19.但是,当我将单元格的Interior.ColorIndex属性设置为等于19时,单元格不是灰色而是灰白色/奶油色。
以下代码实际上将单元格(单元格A1)的颜色从灰色变为奶油色:
Dim r As Range
Set r = Range("A1")
Dim n As Integer
n = r.Interior.ColorIndex
r.Interior.ColorIndex = n
任何人都能解释一下吗?
答案 0 :(得分:2)
我相信ColorIndex
仅支持limited number种颜色。试试这个:
Dim r As Range
Dim n As Long ' The return values are large, so Integer will overflow
Set r = Range("A1")
' The color is 14806254
n = r.Interior.Color
r.Interior.Color = n
或者出于实际目的:
Dim myRange As Range
Dim n As Long
myRange = Range("A1:F1")
n = 14806254
' Color away!
For Each cell In myRange
cell.Interior.Color = n
Next cell
答案 1 :(得分:1)
您还需要设置themecolor。
Dim r As Range
Set r = Range("A1")
Dim n As Integer
n = r.Interior.ColorIndex
With r.Interior
.ColorIndex = n
.ThemeColor = xlThemeColorDark2
End With