|
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Application.EnableEvents = False
With Target
If .Count > 1 Then Exit Sub
If .Column = 2 And .Row > 1 And .Value <> "" Then
.Offset(, 1).Value = .Offset(-1).Value - .Value
If .Offset(, 1).Value < 0 Then
.Offset(, 1).Font.ColorIndex = 3
.Offset(, 1).Interior.ColorIndex = 6
Else
.Offset(, 1).Font.ColorIndex = 0
.Offset(, 1).Interior.ColorIndex = xlNone
End If
ElseIf .Value = "" Then
.Offset(, 1).Font.ColorIndex = 0
.Offset(, 1).Interior.ColorIndex = xlNone
.Offset(, 1).Value = ""
End If
End With
Application.EnableEvents = True
End Sub
|
|