打开excel,在左下角的工作表名字上右键,然后点击“查看代码”

在出来的窗口中,双击左边的“Sheet1”,在打开的窗口中,粘贴下面的代码进去。

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 = 12 '颜色选择,改变该值,行的颜色会改变
End With
With Target.EntireColumn.FormatConditions '列变色
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 12
End With
End Sub
参考:https://zhidao.baidu.com/question/557741756484472612.html
本文介绍如何使用VBA代码实现Excel中行和列的自动变色功能,通过在工作表选择更改时触发事件,自动删除原有的格式条件并添加新的格式条件,使选中的行和列变为特定颜色。
1508

被折叠的 条评论
为什么被折叠?



