在Excel中单击鼠标来更改单元格的颜色 [英] Change color of cell with mouse click in Excel

查看:952
本文介绍了在Excel中单击鼠标来更改单元格的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个工作表,我们的员工可以点击单元格,突出显示它们正在处理任务,然后再次单击它,如果他们需要,再次点击它清除亮点。到目前为止,我已经提出了以下的工作,除了我必须单击另一个单元格,再次回到同一个单元格,否则将尝试编辑单元格。我只想要1点击颜色更改,另一个单击相同的单元格颜色更改2,另一个单击相同的单元格颜色更改3.有什么办法吗?

  Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'如果目标单元格清除
如果Target.Interior.ColorIndex = xlNone然后

'然后更改指定颜色的背景
Target.Interior.ColorIndex = 6

'但是如果目标单元格已经是指定的颜色
ElseIf Target.Interior.ColorIndex = 6 Then

'然后将背景更改为指定的颜色
Target.Interior.ColorIndex = 3

'但是如果目标单元格已经是指定的颜色
ElseIf Target.Interior.ColorIndex = 3然后

'然后清除背景颜色
Target.Interior.ColorIndex = xlNone

结束If
End Sub


解决方案

在同一张表中添加一个BeforeDoubleClick事件与此代码:

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

取消= True
Worksheet_SelectionChange目标

End Sub


I am trying to create a sheet where our employees can click on a cell to highlight it notating they are working of the task, and then click it again when they are finished with it, and click it a 3rd time if they need to clear the highlight. So far I have come up with the below, which works except that I have to click another cell and come back to the same one again or it will try to edit the cell. I Just want 1 click color change, another click same cell color change 2, another click same cell color change 3. Is there any way to do this?

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

解决方案

Add a BeforeDoubleClick event with this code in the same sheet:

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

    Cancel = True
    Worksheet_SelectionChange Target

End Sub

这篇关于在Excel中单击鼠标来更改单元格的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆