Macro to invert sign [Closed]

Report
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-
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 reply

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
767
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

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!