打开excel,右击页面底部的sheet页,选择“查看代码”
2、复制下方的代码,粘贴进去
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 = 35 '颜色选择,改变该值,行的颜色会改变
End With
With Target.EntireColumn.FormatConditions '列变色
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 35
End With
End Sub
3.关闭代码编辑器。回到表格页面,此时选中任何一个单元格,其行和列都会变化颜色