本文讲解如何用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

















- 最新
- 最热
只看作者