Frank Kabel said:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
On Error GoTo CleanUp:
With Target
If .Value <> "" Then
if .value <0 then .value = - .value
End If
End With
CleanUp:
Application.EnableEvents = True
End Sub
...
First things first. While the colon ending the 'On Error' line is
innocuous, it's bad form.
The error trap is nice, but you're missing the critical
Application.EnableEvents = False
call. Also, the OP wants to force *negative* values. Your If block
changes the sign of negative values, thus forcing positive values.
Finally, why bail when Target.Cells.Count > 1? All that means is that
the user entered more than one cell at once, either entering a
multicell array formula or entering into several cells with
[Ctrl]+[Enter]. If the former, probably unwise to try changing the
cell. If the latter, there's no reason not to change the cell.
Perhaps you meant something like
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
With Me.Range("A1")
If .HasArray Then If .CurrentArray.Cells.Count > 1 Then _
Exit Sub
Application.EnableEvents = False
If VarType(.Value) = vbDouble And CDbl(.Value) > 0 Then _
.Value = -.Value
Application.EnableEvents = True
End With
End Sub