VBA 颜色

1. ColorIndex

1-1. ColorIndex的值是从1到56。

Option Explicit

Const MAX_COL As Long = 8
Const MAX_ROW As Long = 2
Const START_ROW As Long = 2
Const START_COL As Long = 2

Sub Color()
    Dim i As Integer
    Dim intRow As Long, intCol As Long
    
    Cells.Select
    Selection.ClearContents
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    
    For i = 1 To 56
        intRow = Int((i / MAX_COL) - 0.0000001)
        intCol = IIf(i Mod MAX_COL = 0, MAX_COL, i Mod MAX_COL) + START_COL - 1
        
        'Color
        Cells((intRow * MAX_ROW) + START_ROW, START_COL).Value = "Color"
        Cells((intRow * MAX_ROW) + START_ROW, intCol).Offset(, 1).Interior.colorIndex = i
        '.ColorIndex
        Cells((intRow * MAX_ROW) + START_ROW, START_COL).Offset(1).Value = "Index"
        Cells((intRow * MAX_ROW) + START_ROW, intCol).Offset(1, 1).Value = i
        
    Next i
    
    Range("A1").Select
    
End Sub

1-2. 运行结果如下

2. QBColor

2-1. QBColor的值是从0到15。

Sub sbQBColor()
    Dim i As Long
    
    Cells.Select
    Selection.ClearContents
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    
    For i = 0 To 15
        Range("B" & i + 2).Value = i
        Range("C" & i + 2).Interior.Color = VBA.QBColor(i)
    Next i
    
    Range("A1").Select
    
End Sub

2-2. 运行结果如下

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值