首页 > 解决方案 > VBA方法查看单元格是否改变颜色?

问题描述

我正在尝试更新我用来突出显示电子表格中的值的简短宏。是否存在检查细胞状态的方法?如果文本得到更新,我想将单元格的颜色改回白色。我不想只是将电子表格中的所有其他颜色都更改为白色,这不是一个有效的案例,因为我还有其他想要保留的颜色。我只想检查:

如果颜色已更改并且不再是有效案例,则将单元格重新着色为白色...

Private Sub CommandButton1_Click()
 Dim itm As Range

    Application.ScreenUpdating = False


    For Each itm In ActiveSheet.UsedRange.Offset(1)
        If Not IsError(itm) Then
            With itm
                Select Case .Value2
                    Case "GREEN", "green", "Green"
                        .Interior.Color = XlRgbColor.rgbLightGreen
                    Case "RED", "red", "Red"
                        .Interior.Color = XlRgbColor.rgbRed
                    Case "Serverely Delayed"
                        .Interior.Color = XlRgbColor.rgbRed
                    Case "Yellow", "yellow", "Yellow"
                        .Interior.Color = XlRgbColor.rgbYellow
                    Case "Delayed", "delayed"
                        .Interior.Color = XlRgbColor.rgbYellow
                    Case "Complete", "complete"
                        .Interior.Color = RGB(153, 204, 0)

                End Select
            End With
        End If
    Next
    Application.ScreenUpdating = True

End Sub

标签: excelvba

解决方案


推荐阅读