Excel_VBA common code

After editing the cell change the background color (No. 6, 355 832 828)

 1 Dim oldvalue As Variant
 2 
 3 Private Sub Worksheet_Change(ByVal Target As Range)
 4     On Error Resume Next
 5     If oldvalue <> Target.Value Then
 6         With Target.Cells.FormatConditions
 7             .Delete
 8             .Add xlExpression, , "TRUE"
 9             .Item(1).Interior.ColorIndex = 9
10         End With
11     End If
12 End Sub
13 
14 Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
15     oldvalue = Target.Value
16 End Sub

 

Guess you like

Origin www.cnblogs.com/yzhyingcool/p/11028406.html