关于excel vba,选中变色,光标离开还原

2024-11-16 12:44:58
推荐回答(1个)
回答(1):

打开EXCEL 进入VBA 双击对应的工作表 将代码复制进去
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Cells.FormatConditions.Delete
With Target.EntireRow.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 3

End With
With Target.EntireColumn.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 3

End With

End Sub