Excel - VBA 根据内容填充cell颜色

Sub RectangleBeveled3_Click()
    Dim rNo, rStart As Integer
    Dim cNo, cStart As Integer
    cNo = Worksheets(1).UsedRange.Columns.Count
    rNo = Worksheets(1).UsedRange.Rows.Count
    cStart = 10
    rStart = 8
    
    Rem MsgBox ("cNo:" & cNo & " " & "rNo:" & rNo & "")
    Rem End
    
    Dim iValue, iPlanStart, iPlanEnd As Date
    Dim iStatus As String

    For a = rStart To rNo 'from row8 to rowMax
        iStatus = LCase(Cells(a, 4))
        iPlanStart = Cells(a, 6)
        iPlanEnd = Cells(a, 7)
        For b = cStart To cNo 'from column8 to columnDMax
            Rem MsgBox ("Row:" & a & "\nr" & "Col:" & b & "\nr")
            Rem Exit For

            iValue = Cells(6, b)
            If iValue <= iPlanEnd And iValue >= iPlanStart Then
                If iStatus = "ongoing" Then
                    Cells(a, b).Interior.Color = RGB(255, 255, 0) 'yellow color
                ElseIf iStatus = "done" Then
                    Cells(a, b).Interior.Color = RGB(0, 176, 80) 'green color
                ElseIf iStatus = "blocked" Then
                    Cells(a, b).Interior.Color = RGB(255, 0, 0) 'red color
                Else
                    'nothing
                End If
                
            Else
                Cells(a, b).Interior.Color = RGB(255, 255, 255) 'white color
            End If
            If b = 20 Then
                Rem MsgBox ("Row:" & a & "\nr" & "Col:" & b & "\nr")
                Rem Exit For
            End If
        Next
    

    Next
    a = a - 1
    b = b - 1
    Dim CNtoW As String
    CNtoW = Replace(Cells(1, b).Address(False, False), "1", "") ' convert number to column alphabet
    Set Rng = Range("J8:" & CNtoW & a)
    Rng.Borders.LineStyle = xlHairline

    MsgBox ("Finish")
End Sub
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值