Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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/ |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I convert a column of positive numbers to negitive numbers | Excel Worksheet Functions | |||
Excel 2002 : Convert Positive Numbers to Negative Numbers ? | Excel Discussion (Misc queries) | |||
Convert numbers stored as text to numbers Excel 2000 | Excel Discussion (Misc queries) | |||
convert negative numbers to positive numbers and vice versa | Excel Worksheet Functions | |||
How to convert Excel imported numbers from text to numbers? | Excel Discussion (Misc queries) |