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

use*_*079 5 excel vba

我正在尝试创建一个工作表,我们的员工可以在其中单击一个单元格以突出显示它,表明他们正在执行任务,然后在完成任务后再次单击它,如果他们需要清除该任务,则第三次单击它强调。到目前为止,我已经提出了以下内容,除了我必须单击另一个单元格并再次返回相同的单元格,否则它将尝试编辑该单元格。我只想要 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 = xlNone

    End If    
End Sub
Run Code Online (Sandbox Code Playgroud)

tig*_*tar 5

在同一工作表中使用以下代码添加 BeforeDoubleClick 事件:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Cancel = True
    Worksheet_SelectionChange Target

End Sub
Run Code Online (Sandbox Code Playgroud)