Excel 2003,我想通过点击鼠标来改变单元格的颜色。我已经完成了,我的问题是如何在单元格上单击鼠标后再次获得原始颜色。我希望能够将单元格的颜色从白色更改为绿色,并且每次单击鼠标时都会再次更改颜色。用鼠标单击改变单元格的颜色
0
A
回答
3
这是我在我的一张床单上使用的。基本上用户双击单元格以创建用户表单;并在提交更正时突出显示细胞黄色。如果他们犯了一个错误,他们双击删除高亮。你应该能够在下面的代码中找出你所需要的。每下面的评论
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.EnableEvents = False
Dim TargRow As Variant
Dim TargCol As Variant
TargRow = Target.Row
TargCol = Target.Column
Header = 8
FirstCol = 0
LastCol = 13
CommentCol = 13
If TargRow > Header And TargCol > FirstCol And TargCol < LastCol Then
'If the cell is clear
If Target.Interior.ColorIndex = xlNone Then
Cancel = True
'Then change the background to yellow
Target.Interior.ColorIndex = 6
Corrections.Show
'Else if the cell background color is already yellow
ElseIf Target.Interior.ColorIndex = 6 Then
'Then clear the background
Target.Interior.ColorIndex = xlNone
End If
End If
'This is to prevent the cell from being edited when double-clicked
Cancel = True
Application.EnableEvents = True
End Sub
编辑的代码:
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 = 4
'But if the target cell is already the specified color
ElseIf Target.Interior.ColorIndex = 4 Then
'Then clear the background color
Target.Interior.ColorIndex = xlNone
End If
End Sub
+0
感谢您的回复(以“这个我做了”暗示的),但我仍然有问题。我试图将这个应用于特定的单元格。我现在拥有如下: – 2012-01-09 21:43:50
+0
好的。我砍掉了上面的东西,并改变了放在哪里。该代码作为SelectionChange事件放置在工作表上。它只需要你点击一个单元格(而不是像上面那样双击);点击单元格将单元格变成绿色 - 单击单元格再次清除颜色。此外,细胞仍然可以编辑,不像我上面的原始答案。请参阅上面的代码编辑答案。 – Jon 2012-01-10 13:44:56
相关问题
- 1. 如何在鼠标点击后用颜色填充单元格?
- 2. 防止改变颜色的单元格再次改变颜色
- 3. 单击和鼠标悬停时更改元素的颜色
- 4. 当单元格中的值改变单元格颜色
- 5. 更改单元格颜色
- 6. 更改单元格颜色
- 7. 如何更改表格中单击单元格的单元格背景颜色?
- 8. 如何使用鼠标单击填充html表格使颜色与颜色?
- 9. 改变ui主题颜色和鼠标点击鼠标悬停?
- 10. JfreeChart:鼠标单击事件的颜色变化
- 11. 通过单击c#(winform)更改datagridview单元格颜色
- 12. 单击AdvancedDataGrid单元格并更改其颜色
- 13. 单击编辑按钮时更改单元格颜色
- 14. 在单选按钮单击后,取消更改表格单元格的颜色
- 15. jquery更改表格单元格颜色
- 16. Haskell,在鼠标单击时更改绘制颜色
- 17. 当单元格选中时更改单元格的颜色
- 18. 更改JTable中单元格的颜色
- 19. Setinterval更改单元格的颜色
- 20. Tkintertable更改单元格/行的颜色
- 21. 更改dataGridView单元格中的颜色
- 22. 变化的UITableView单元格颜色
- 23. Silverlight的数据网格:改变某些单元格的颜色
- 24. jQuery的:改变一个表格单元格的边框颜色
- 25. 在JQGrid中更改单元格颜色,同时点击单元格
- 26. 用鼠标点击改变JPanel的颜色
- 27. EXTJS/HTML - 动态改变html表格单元格的颜色
- 28. 导航鼠标点击改变颜色,在鼠标的div使用jQuery
- 29. 根据标题更改表格单元格的背景颜色
- 30. 基于另一个单元格值更改单元格颜色
请发表您的当前代码 – brettdj 2012-01-10 02:09:42