VBA代码用于引入单元格的背景颜色

时间:2014-06-18 16:29:03

标签: excel-vba vba excel

我试图弄清楚是否有代码可以复制单元格的背景颜色。例如,单元格a1的背景颜色为白色,但我决定要将该单元格突出显示为黄色,是否可以通过vba代码将该颜色格式化?

1 个答案:

答案 0 :(得分:0)

试试这个:

Sub Macro1()
    Range("A1").Style = "Neutral" 'select whatever cell you want to change
    'this style is kinda yellow
    Range("A2").Style = "Accent6" 'select whatever cell you want to change
    'this style is orange
    'you will have to use whatever accent you want
End Sub

你必须根据自己的需要调整它。如果这有帮助,请告诉我!

刚试过别的东西。这个实际上改变了填充颜色,而不仅仅是样式。

Range("A3").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With