小编use*_*079的帖子

在 Excel 中单击鼠标更改单元格的颜色

我正在尝试创建一个工作表,我们的员工可以在其中单击一个单元格以突出显示它,表明他们正在执行任务,然后在完成任务后再次单击它,如果他们需要清除该任务,则第三次单击它强调。到目前为止,我已经提出了以下内容,除了我必须单击另一个单元格并再次返回相同的单元格,否则它将尝试编辑该单元格。我只想要 1 单击颜色更改,再次单击相同的单元格颜色更改 2,再次单击相同的单元格颜色更改 3。有什么办法可以做到这一点?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)    
  'If the target cell is clear
     If Target.Interior.ColorIndex = xlNone Then

        'Then change the background to the specified color
        Target.Interior.ColorIndex = 6

        'But if the target cell is already the specified color
        ElseIf Target.Interior.ColorIndex = 6 Then

        'Then change the background to the specified color
        Target.Interior.ColorIndex = 3

        'But if the target cell is already the specified color
        ElseIf Target.Interior.ColorIndex = 3 Then

        'Then clear the background color
        Target.Interior.ColorIndex …
Run Code Online (Sandbox Code Playgroud)

excel vba

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

excel ×1

vba ×1