ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert -ve numbers to +ve (https://www.excelbanter.com/excel-programming/283921-convert-ve-numbers-ve.html)

ali

Convert -ve numbers to +ve
 

I often have to work with sheets that contain awkward negative number
and it would make my life much easier if i could use a macro that woul
search a column and convert any negative numbers into positiv
numbers.

Can anyone help my with how i can do this please?

Alternatively if anyone can tell me how to convert positive numbers t
negative that would be equally useful.

Many thank

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com


Chip Pearson[_2_]

Convert -ve numbers to +ve
 
Ali,

Try something like the following:

Sub MakePositive()
Dim Rng As Range
For Each Rng In
ActiveSheet.UsedRange.SpecialCells(xlCellTypeConst ants,
xlNumbers)
If Rng.Value < 0 Then
Rng.Value = Abs(Rng.Value)
End If
Next Rng
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"ali" wrote in message
...

I often have to work with sheets that contain awkward negative

numbers
and it would make my life much easier if i could use a macro

that would
search a column and convert any negative numbers into positive
numbers.

Can anyone help my with how i can do this please?

Alternatively if anyone can tell me how to convert positive

numbers to
negative that would be equally useful.

Many thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/




Don Guillett[_4_]

Convert -ve numbers to +ve
 
this should work

For Each c In Selection
c.Value = Abs(c)
Next
--
Don Guillett
SalesAid Software

"ali" wrote in message
...

I often have to work with sheets that contain awkward negative numbers
and it would make my life much easier if i could use a macro that would
search a column and convert any negative numbers into positive
numbers.

Can anyone help my with how i can do this please?

Alternatively if anyone can tell me how to convert positive numbers to
negative that would be equally useful.

Many thanks


------------------------------------------------
~~ Message posted from
http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/




Dave Peterson[_3_]

Convert -ve numbers to +ve
 
select your range and then run this:

Option Explicit
Sub testme01()
Dim myCell As Range
Dim myRange As Range

On Error Resume Next
Set myRange = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlNumbers))
On Error GoTo 0

If myRange Is Nothing Then
MsgBox "Select a range with number values"
Exit Sub
End If

For Each myCell In myRange.Cells
If myCell.Value < 0 Then
myCell.Value = -myCell.Value
End If
Next myCell

End Sub

And if you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

ali wrote:

I often have to work with sheets that contain awkward negative numbers
and it would make my life much easier if i could use a macro that would
search a column and convert any negative numbers into positive
numbers.

Can anyone help my with how i can do this please?

Alternatively if anyone can tell me how to convert positive numbers to
negative that would be equally useful.

Many thanks

------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/


--

Dave Peterson


ali

Convert -ve numbers to +ve
 

Thanks very much for all the help - you've saved me a lot of time an
stress!!

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com



All times are GMT +1. The time now is 10:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com