如何根据值进行单元格颜色更改

时间:2016-08-06 20:14:45

标签: excel excel-vba colors cell vba

  Dim c As Range
 Application.ScreenUpdating = False
 For Each c In Range("G1", Range("G" & Rows.Count).End(xlUp))


 If Left(c, 1) = "X" Then c = Mid(c, 2, Len(c) - 1)
 If Left(c, 1) = "L" Then c = Mid(c, 2, Len(c) - 1)
 If Left(c, 1) = "C" Then c = Mid(c, 2, Len(c) - 1)


Next c
Application.ScreenUpdating = True

如何在满足条件后让细胞改变内部颜色(让我们说浅蓝色)?

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

使用:c.Interior.colorIndex = 8

可以找到颜色代码列表here

修改

根据您的意见,完整的代码将是:

 Dim c As Range
 Application.ScreenUpdating = False
 For Each c In Range("G1", Range("G" & Rows.Count).End(xlUp))

     If Left(c, 1) = "X" Or Left(c, 1) = "L" Or Left(c, 1) = "C" Then
        c = Mid(c, 2, Len(c) - 1)
        c.Interior.ColorIndex = 8
     End If

Next c
Application.ScreenUpdating = True