Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) On Error Resume Next Cells.FormatConditions.Delete iColor = 34 With Target.EntireRow.FormatConditions .Delete .Add xlExpression, , "TRUE" .Item
(1).Interior.ColorIndex = iColor End With With Target.EntireColumn.FormatConditions .Delete .Add xlExpression, , "TRUE" .Item(1).Interior.ColorIndex = iColor End WithEnd Sub
設定電子表格,隨著滑鼠點的位置出現別的顏色的步驟:
1、首先,我們需要開啟excel,新建如下圖。
3、選擇檢視程式碼。
4、看到如下介面,插入如下程式碼。
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) On Error Resume Next Cells.FormatConditions.Delete iColor = 34 With Target.EntireRow.FormatConditions .Delete .Add xlExpression, , "TRUE" .Item
(1).Interior.ColorIndex = iColor End With With Target.EntireColumn.FormatConditions .Delete .Add xlExpression, , "TRUE" .Item(1).Interior.ColorIndex = iColor End WithEnd Sub
5、儲存,可以看到,如下效果了,當滑鼠點到哪裡,哪裡就會有顏色。