Small macro to convert value

lapta301

Well-known Member
Joined
Nov 12, 2004
Messages
987
Office Version
  1. 365
Platform
  1. Windows
Hi all

I have a recurring need to convert a large number values that come in from another system and it would be helpful to be able to do this by way of a small macro.

What I would like if possible is for a macro to run on a range of cells selected by me at run time and then convert all of the values - negative values to positive and positive to negative.

I hope this makes sense and as ever any help would be very much appreciated.
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

stumac

Active Member
Joined
Jul 16, 2010
Messages
471
if you multiply the value by -1 or deduct it from 0 then it will change from positive to negative/vice versa

Code:
Sub ChangeSign()
For Each c In Selection.Cells
    If IsNumeric(c.Value) Then
        c.Value = 0 - c.Value
    End If
Next c
End Sub
 
Last edited:

lapta301

Well-known Member
Joined
Nov 12, 2004
Messages
987
Office Version
  1. 365
Platform
  1. Windows
Thanks stumac it works a treat much appreciated
 

Watch MrExcel Video

Forum statistics

Threads
1,109,000
Messages
5,526,186
Members
409,686
Latest member
Tori83

This Week's Hot Topics

Top