Convert -ve numbers to +ve

  • Thread starter Thread starter ali
  • Start date Start date
A

ali

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
 
Ali,

Try something like the following:

Sub MakePositive()
Dim Rng As Range
For Each Rng In
ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants,
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
 
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
 
Back
Top