VBA改变单元格颜色的几种方法

本文讲解如何用VBA改变单元格背景色。

用Interior.ColorIndex改变单元格背景色

要在VBA中改变单元格背景色,可以使用Interior.ColorIndex属性。

通过Range对象的Interior.ColorIndex属性

Range("A1").Interior.ColorIndex = 5

通过Cells对象的Interior.ColorIndex属性

Cells(1, 1).Interior.ColorIndex = 15

清除背景色

只需要把ColorIndex赋值为0即可。

Range("A1").Interior.ColorIndex = 0
' 或者
Cells("A1").Interior.ColorIndex = 0

用Interior.Color改变单元格背景色

也可以用Interior.Color直接给单元格背景色设置颜色,颜色值通过RGB(red, green, blue)函数设置,red/green/blue的取值都在0-255范围内。

Range("A1").Interior.Color = RGB(10, 200, 200)
' 或者
Cells("A1").Interior.ColorIndex = RGB(10, 200, 200)
© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 共2条

请登录后发表评论