macro code to change positive numbers into negative numbers

jts2004

Board Regular
Joined
Apr 21, 2004
Messages
156
I know ASAP has a feature to do this but I need the code in a bigger macro that I wrote.

EX: -1 needs to be 1
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Ok, in your title you say "change positive numbers into negative numbers", but in your example you do the opposite. This code change positive figures into negatives (does not change negatives).

If [a1].Value > 0 Then [a1].Value = [a1].Value * -1
 
Upvote 0
couldn't you multiply ANY number (both positive and negative) by -1...and that reverses the cosign?

in other words

-1 * -1 = 1
1 * -1 = -1

-35 * -1 = 35
35 * -1 = -35

Am I thinking to simple??

so you could just use formulas
=A1*-1
and fill down

that will reverse the cosigns...

if you ONLY want to change negatives to positives...it would be

=abs(a1) <---edited found better way than the IF statement.

or if you wanted to change positive to negative

=-abs(a1)
 
Upvote 0
in code, you can also use the ABS Function...

Range("A1").Value = Abs(Range("A1"))
 
Upvote 0
in code, you can also use the ABS Function...

Range("A1").Value = Abs(Range("A1"))

I actually need it to work just like the ASAP utility function becuase its in a bigger macro
 
Upvote 0
Well, without more details, you can do an entire range like so...
Code:
Sub test()
For Each Cell In Range("a1:z100")
If Cell.Value < 0 Then
    Cell.Value = Abs(Cell.Value)
End If
Next Cell
End Sub

this will change any negative numbers in range A1:Z100 to Positive.
 
Upvote 0
Code:
Sub test() 
For Each Cell In Range("a1:z100") 
If Cell.Value > 0 Then 
    Cell.Value = cell.value * -1 
End If 
Next Cell 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,889
Messages
6,122,097
Members
449,065
Latest member
albertocarrillom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top