在Excel中单击鼠标来更改单元格的颜色 [英] Change color of cell with mouse click in Excel
本文介绍了在Excel中单击鼠标来更改单元格的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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屋!
查看全文