在EXCEl中,用VBA实现单元格颜色改变

2024-10-22 13:59:24
有4个网友回答
网友(1):

代码如下:

   

Sub ts()

Dim rg As Range

Dim r As Long

r = Columns("A:C").SpecialCells(xlLastCell).Row

For Each rg In Range("A1:C" & r)

    If rg < Range("E" & rg.Row) Then

        rg.Interior.Color = RGB(255, 0, 0)

    Else

        rg.Interior.Color = RGB(146, 208, 80)

    End If

Next

End Sub

   

网友(2):

这儿就能搞定了  不需要VBA

网友(3):

dim i%,r%
Whit Sheets["表名称"]
r=.Range["A65536"].End(xlup).Row
For i=1 to r
If .Cells(i,1) .Value<20 Then
.Cells(i,1).Font.ColorIndex=4
Eed If
If .Cells(i,1) .Value>19 And .Cells(i,1) .Value<41 Then
.Cells(i,1).Font.ColorIndex=6
End If
If .Cells(i,1) .Value>40 Then
.Cells(i,1).Font.ColorIndex=3
End If
Next i
End With

网友(4):

条件格式就能搞定了,舍易求难啊