如何用宏程序实现EXCEL表格的着色与取消

来源:百度知道 编辑:UC知道 时间:2024/06/17 11:47:46
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim icolor As Integer
On Error Resume Next
Cells.FormatConditions.Delete
icolor = 3
With Target.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = icolor
End With
End Sub
.,我有一个小程序实现了着色,但是还差一个语句,第二次点击空格则颜色取消.急高手能帮我修改一下.
点一个空格着色,再点这个空格,取消颜色;可以同时保存一行最少五个空格的颜色,(意思就是点一次保存,点第二次取消!)求高手做嫁衣!

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim icolor As Integer
On Error Resume Next
' Cells.FormatConditions.Delete
icolor = 3
With Target.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = icolor
End With
End Sub