Macro to invert sign

Closed
Vicki - Jun 7, 2010 at 06:26 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Jun 7, 2010 at 06:52 PM
Hello,

I need a macro that will flip a positive to a negative and vice verse. I had the following but it stopped working all of a sudden...

Dim Cel As Range
For Each Cel In Selection
If IsNumeric(Cel.Value) Then
If Cel.Value < 0 Then
Cel.Value = Abs(Cel.Value)
Else: Cel.Value = Abs(Cel.Value) * (-1)
End If
Next Cel
End Sub

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jun 7, 2010 at 06:52 PM
A macro is not supposed to stop working for no reason. There has to be a cause. Have you tried to debug and step thru the code.

It is same as yours, just a minor tweak

Dim Cell As Range

    For Each Cell In Selection
    
        If (IsNumeric(Cell.Value) And Cell <> "") Then Cell.Value = Cell.Value * -1
    
    Next Cell
0