点击工作表右键——查看代码:
在出来的窗口中,粘贴下面的代码进去。
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
With Target.EntireRow.FormatConditions '行变色
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 8 '颜色选择,改变该值,行的颜色会改变
End With
With Target.EntireColumn.FormatConditions '列变色
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 8
End With
End Sub