这段改变颜色的VBA代码有什么问题?为什么无论改哪个位置都会变色?
Private Sub Worksheet_Change(ByVal Target As Range) Application.EnableEvents = false On Error Goto ENEV REM add your code below If ((Target.Column >= 5) and (Target.Column <= 8)) or (Target.Column >= 14) Then if IsNumeric(Target) then If Target > 0 Then Target.Font.Color = RGB(255,0,0) Elseif Target < 0 Then Target.Font.Color = RGB(0,128,0) Else Target.Font.Color = RGB(128,128,138) End If End if End If ENEV: Application.EnableEvents = trueEnd Sub
Private Sub Worksheet_Change(ByVal Target As Range) Application.EnableEvents = False On Error GoTo ENEV Rem add your code below With Target If ((.Column >= 5) And (.Column <= 8)) Or (.Column >= 14) Then If IsNumeric(Target) Then If .Value > 0 Then .Font.ColorIndex = 3 ElseIf .Value < 0 Then 'Target.Font.Color = RGB(0, 128, 0) .Font.ColorIndex = 10 Else .Font.ColorIndex = 48 End If End If Else .Font.ColorIndex = 0 End If End WithENEV: Application.EnableEvents = TrueEnd Sub