Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ali ali is offline
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default 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   Report Post  
Posted to microsoft.public.excel.programming
ali ali is offline
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert a column of positive numbers to negitive numbers JMason Excel Worksheet Functions 2 January 22nd 09 02:12 AM
Excel 2002 : Convert Positive Numbers to Negative Numbers ? Mr. Low Excel Discussion (Misc queries) 2 November 6th 06 03:30 PM
Convert numbers stored as text to numbers Excel 2000 Darlene Excel Discussion (Misc queries) 6 January 31st 06 08:04 PM
convert negative numbers to positive numbers and vice versa bill gras Excel Worksheet Functions 4 December 7th 05 01:39 AM
How to convert Excel imported numbers from text to numbers? Alden Excel Discussion (Misc queries) 9 April 1st 05 09:51 PM


All times are GMT +1. The time now is 11:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"