PC Review


Reply
Thread Tools Rate Thread

Convert neg. numbers to positive numbers

 
 
=?Utf-8?B?TWljaGFlbGNpcA==?=
Guest
Posts: n/a
 
      22nd Aug 2007
I want to convert neg. numbers to positive numbers. To be clear, I don't
want them just to DISPLAY as positive but to BECOME positive. As well, I
don't want to have to had another column (the ABS() function). Thanks to any
who can help.
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      22nd Aug 2007
How about.

Sub makenegpos()
For Each c In Range("r1:r9")
If c.Value < 0 Then c.Value = -c
Next c
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Michaelcip" <(E-Mail Removed)> wrote in message
news:53B82204-E206-422E-835A-(E-Mail Removed)...
>I want to convert neg. numbers to positive numbers. To be clear, I don't
> want them just to DISPLAY as positive but to BECOME positive. As well, I
> don't want to have to had another column (the ABS() function). Thanks to
> any
> who can help.


 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      22nd Aug 2007
If they are all negative, then put -1 in a spare cell and copy that cell.

Then select the numbers and Edit>PasteSpecial>Multiply

OK out and clear out the -1.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Michaelcip" <(E-Mail Removed)> wrote in message
news:53B82204-E206-422E-835A-(E-Mail Removed)...
>I want to convert neg. numbers to positive numbers. To be clear, I don't
> want them just to DISPLAY as positive but to BECOME positive. As well, I
> don't want to have to had another column (the ABS() function). Thanks to
> any
> who can help.



 
Reply With Quote
 
=?Utf-8?B?Ymo=?=
Guest
Posts: n/a
 
      22nd Aug 2007
If they are all negative put -1 in an empty helper cell and copy it
select all the negatives and paste special multiply
delete the helper cell

"Michaelcip" wrote:

> I want to convert neg. numbers to positive numbers. To be clear, I don't
> want them just to DISPLAY as positive but to BECOME positive. As well, I
> don't want to have to had another column (the ABS() function). Thanks to any
> who can help.

 
Reply With Quote
 
AFSSkier
Guest
Posts: n/a
 
      24th Jun 2009

Don,

I like your example to change Neg to Pos. How do you change Pos to Neg?

I tired the following & it didn't work. I changed only the if statement.

Sub MakePosNeg()
For Each c In Range("A1:ZZ10000")
If c.Value > 0 Then c.Value = c
Next c
End Sub
--
Thanks, Kevin


"Don Guillett" wrote:

> How about.
>
> Sub makenegpos()
> For Each c In Range("r1:r9")
> If c.Value < 0 Then c.Value = -c
> Next c
> End Sub
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "Michaelcip" <(E-Mail Removed)> wrote in message
> news:53B82204-E206-422E-835A-(E-Mail Removed)...
> >I want to convert neg. numbers to positive numbers. To be clear, I don't
> > want them just to DISPLAY as positive but to BECOME positive. As well, I
> > don't want to have to had another column (the ABS() function). Thanks to
> > any
> > who can help.

>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      24th Jun 2009

Try Don's original suggestion.

-c will convert positive to negative and negative to positive.



AFSSkier wrote:
>
> Don,
>
> I like your example to change Neg to Pos. How do you change Pos to Neg?
>
> I tired the following & it didn't work. I changed only the if statement.
>
> Sub MakePosNeg()
> For Each c In Range("A1:ZZ10000")
> If c.Value > 0 Then c.Value = c
> Next c
> End Sub
> --
> Thanks, Kevin
>
> "Don Guillett" wrote:
>
> > How about.
> >
> > Sub makenegpos()
> > For Each c In Range("r1:r9")
> > If c.Value < 0 Then c.Value = -c
> > Next c
> > End Sub
> >
> > --
> > Don Guillett
> > Microsoft MVP Excel
> > SalesAid Software
> > (E-Mail Removed)
> > "Michaelcip" <(E-Mail Removed)> wrote in message
> > news:53B82204-E206-422E-835A-(E-Mail Removed)...
> > >I want to convert neg. numbers to positive numbers. To be clear, I don't
> > > want them just to DISPLAY as positive but to BECOME positive. As well, I
> > > don't want to have to had another column (the ABS() function). Thanks to
> > > any
> > > who can help.

> >
> >


--

Dave Peterson
 
Reply With Quote
 
AFSSkier
Guest
Posts: n/a
 
      24th Jun 2009

Dave,

The neg to pos work great. However, I get the following error when I change
it to > 0. Run-time error '13': Type mismatch. It doesn't like c.Value = -c
--
Thanks, Kevin


"Dave Peterson" wrote:

> Try Don's original suggestion.
>
> -c will convert positive to negative and negative to positive.
>
>
>
> AFSSkier wrote:
> >
> > Don,
> >
> > I like your example to change Neg to Pos. How do you change Pos to Neg?
> >
> > I tired the following & it didn't work. I changed only the if statement.
> >
> > Sub MakePosNeg()
> > For Each c In Range("A1:ZZ10000")
> > If c.Value > 0 Then c.Value = c
> > Next c
> > End Sub
> > --
> > Thanks, Kevin
> >
> > "Don Guillett" wrote:
> >
> > > How about.
> > >
> > > Sub makenegpos()
> > > For Each c In Range("r1:r9")
> > > If c.Value < 0 Then c.Value = -c
> > > Next c
> > > End Sub
> > >
> > > --
> > > Don Guillett
> > > Microsoft MVP Excel
> > > SalesAid Software
> > > (E-Mail Removed)
> > > "Michaelcip" <(E-Mail Removed)> wrote in message
> > > news:53B82204-E206-422E-835A-(E-Mail Removed)...
> > > >I want to convert neg. numbers to positive numbers. To be clear, I don't
> > > > want them just to DISPLAY as positive but to BECOME positive. As well, I
> > > > don't want to have to had another column (the ABS() function). Thanks to
> > > > any
> > > > who can help.
> > >
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      24th Jun 2009

I bet that the cell that caused the trouble wasn't a cell that contained a
number.

So you can add a check:

> > > Sub MakePosNeg()
> > > For Each c In Range("A1:ZZ10000")

if isnumeric(c.value) then
> > > If c.Value > 0 Then

c.Value = -c.value
end if
end if
> > > Next c
> > > End Sub


I like the block style "if/end if". I changed Don's original suggestion, but it
won't matter.



AFSSkier wrote:
>
> Dave,
>
> The neg to pos work great. However, I get the following error when I change
> it to > 0. Run-time error '13': Type mismatch. It doesn't like c.Value = -c
> --
> Thanks, Kevin
>
> "Dave Peterson" wrote:
>
> > Try Don's original suggestion.
> >
> > -c will convert positive to negative and negative to positive.
> >
> >
> >
> > AFSSkier wrote:
> > >
> > > Don,
> > >
> > > I like your example to change Neg to Pos. How do you change Pos to Neg?
> > >
> > > I tired the following & it didn't work. I changed only the if statement.
> > >
> > > Sub MakePosNeg()
> > > For Each c In Range("A1:ZZ10000")
> > > If c.Value > 0 Then c.Value = c
> > > Next c
> > > End Sub
> > > --
> > > Thanks, Kevin
> > >
> > > "Don Guillett" wrote:
> > >
> > > > How about.
> > > >
> > > > Sub makenegpos()
> > > > For Each c In Range("r1:r9")
> > > > If c.Value < 0 Then c.Value = -c
> > > > Next c
> > > > End Sub
> > > >
> > > > --
> > > > Don Guillett
> > > > Microsoft MVP Excel
> > > > SalesAid Software
> > > > (E-Mail Removed)
> > > > "Michaelcip" <(E-Mail Removed)> wrote in message
> > > > news:53B82204-E206-422E-835A-(E-Mail Removed)...
> > > > >I want to convert neg. numbers to positive numbers. To be clear, I don't
> > > > > want them just to DISPLAY as positive but to BECOME positive. As well, I
> > > > > don't want to have to had another column (the ABS() function). Thanks to
> > > > > any
> > > > > who can help.
> > > >
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
AFSSkier
Guest
Posts: n/a
 
      25th Jun 2009

Dave,

You are correct; the generic range does include text. Your suggestion
works. However because A1:ZZ10000 is a generic range, all non-numeric fields
change.

Is there a way to preselect a range (for example E6:M100 or G2:K2000) before
running the generic macro to change pos to neg?

I realize it's safer to go from neg to pos with a generic macro. But we
have some instances where we need to fix data entered wrong (chg pos to neg).

--
Thanks, Kevin


"Dave Peterson" wrote:

> I bet that the cell that caused the trouble wasn't a cell that contained a
> number.
>
> So you can add a check:
>
> > > > Sub MakePosNeg()
> > > > For Each c In Range("A1:ZZ10000")

> if isnumeric(c.value) then
> > > > If c.Value > 0 Then

> c.Value = -c.value
> end if
> end if
> > > > Next c
> > > > End Sub

>
> I like the block style "if/end if". I changed Don's original suggestion, but it
> won't matter.
>
>
>
> AFSSkier wrote:
> >
> > Dave,
> >
> > The neg to pos work great. However, I get the following error when I change
> > it to > 0. Run-time error '13': Type mismatch. It doesn't like c.Value = -c
> > --
> > Thanks, Kevin
> >
> > "Dave Peterson" wrote:
> >
> > > Try Don's original suggestion.
> > >
> > > -c will convert positive to negative and negative to positive.
> > >
> > >
> > >
> > > AFSSkier wrote:
> > > >
> > > > Don,
> > > >
> > > > I like your example to change Neg to Pos. How do you change Pos to Neg?
> > > >
> > > > I tired the following & it didn't work. I changed only the if statement.
> > > >
> > > > Sub MakePosNeg()
> > > > For Each c In Range("A1:ZZ10000")
> > > > If c.Value > 0 Then c.Value = c
> > > > Next c
> > > > End Sub
> > > > --
> > > > Thanks, Kevin
> > > >
> > > > "Don Guillett" wrote:
> > > >
> > > > > How about.
> > > > >
> > > > > Sub makenegpos()
> > > > > For Each c In Range("r1:r9")
> > > > > If c.Value < 0 Then c.Value = -c
> > > > > Next c
> > > > > End Sub
> > > > >
> > > > > --
> > > > > Don Guillett
> > > > > Microsoft MVP Excel
> > > > > SalesAid Software
> > > > > (E-Mail Removed)
> > > > > "Michaelcip" <(E-Mail Removed)> wrote in message
> > > > > news:53B82204-E206-422E-835A-(E-Mail Removed)...
> > > > > >I want to convert neg. numbers to positive numbers. To be clear, I don't
> > > > > > want them just to DISPLAY as positive but to BECOME positive. As well, I
> > > > > > don't want to have to had another column (the ABS() function). Thanks to
> > > > > > any
> > > > > > who can help.
> > > > >
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th Jun 2009

I'd use something like:

Option Explicit
Sub MakePosNeg()
Dim myCell As Range
Dim Rng As Range

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

If Rng Is Nothing Then
MsgBox "No constant numbers found in selection."
Exit Sub
End If

For Each myCell In Rng.Cells
If myCell.Value > 0 Then
myCell.Value = -myCell.Value
End If
Next myCell
End Sub


That .specialcells stuff does the same thing as selecting a larger range and
hitting F5 (or Edit|Goto in xl2003 menus). Then Special, then Constants and
Numbers (and unchecking all those other options.

That means you don't have to be as careful selecting the range and it'll be a
little faster--it'll have fewer cells to loop through (usually).

AFSSkier wrote:
>
> Dave,
>
> You are correct; the generic range does include text. Your suggestion
> works. However because A1:ZZ10000 is a generic range, all non-numeric fields
> change.
>
> Is there a way to preselect a range (for example E6:M100 or G2:K2000) before
> running the generic macro to change pos to neg?
>
> I realize it's safer to go from neg to pos with a generic macro. But we
> have some instances where we need to fix data entered wrong (chg pos to neg).
>
> --
> Thanks, Kevin
>
> "Dave Peterson" wrote:
>
> > I bet that the cell that caused the trouble wasn't a cell that contained a
> > number.
> >
> > So you can add a check:
> >
> > > > > Sub MakePosNeg()
> > > > > For Each c In Range("A1:ZZ10000")

> > if isnumeric(c.value) then
> > > > > If c.Value > 0 Then

> > c.Value = -c.value
> > end if
> > end if
> > > > > Next c
> > > > > End Sub

> >
> > I like the block style "if/end if". I changed Don's original suggestion, but it
> > won't matter.
> >
> >
> >
> > AFSSkier wrote:
> > >
> > > Dave,
> > >
> > > The neg to pos work great. However, I get the following error when I change
> > > it to > 0. Run-time error '13': Type mismatch. It doesn't like c.Value = -c
> > > --
> > > Thanks, Kevin
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > Try Don's original suggestion.
> > > >
> > > > -c will convert positive to negative and negative to positive.
> > > >
> > > >
> > > >
> > > > AFSSkier wrote:
> > > > >
> > > > > Don,
> > > > >
> > > > > I like your example to change Neg to Pos. How do you change Pos to Neg?
> > > > >
> > > > > I tired the following & it didn't work. I changed only the if statement.
> > > > >
> > > > > Sub MakePosNeg()
> > > > > For Each c In Range("A1:ZZ10000")
> > > > > If c.Value > 0 Then c.Value = c
> > > > > Next c
> > > > > End Sub
> > > > > --
> > > > > Thanks, Kevin
> > > > >
> > > > > "Don Guillett" wrote:
> > > > >
> > > > > > How about.
> > > > > >
> > > > > > Sub makenegpos()
> > > > > > For Each c In Range("r1:r9")
> > > > > > If c.Value < 0 Then c.Value = -c
> > > > > > Next c
> > > > > > End Sub
> > > > > >
> > > > > > --
> > > > > > Don Guillett
> > > > > > Microsoft MVP Excel
> > > > > > SalesAid Software
> > > > > > (E-Mail Removed)
> > > > > > "Michaelcip" <(E-Mail Removed)> wrote in message
> > > > > > news:53B82204-E206-422E-835A-(E-Mail Removed)...
> > > > > > >I want to convert neg. numbers to positive numbers. To be clear, I don't
> > > > > > > want them just to DISPLAY as positive but to BECOME positive. As well, I
> > > > > > > don't want to have to had another column (the ABS() function). Thanks to
> > > > > > > any
> > > > > > > who can help.
> > > > > >
> > > > > >
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert a column of positive numbers to negitive numbers JMason Microsoft Excel Worksheet Functions 1 22nd Jan 2009 02:12 AM
Excel 2002 : Convert Positive Numbers to Negative Numbers ? =?Utf-8?B?TXIuIExvdw==?= Microsoft Excel Misc 2 6th Nov 2006 03:30 PM
convert numbers to positive and keep delta value =?Utf-8?B?bm9sZW5rdw==?= Microsoft Excel Misc 3 11th Aug 2006 05:15 PM
convert negative numbers to positive numbers and vice versa =?Utf-8?B?YmlsbCBncmFz?= Microsoft Excel Worksheet Functions 4 7th Dec 2005 01:39 AM
Convert positive numbers to negative Anita Microsoft Excel Worksheet Functions 7 21st Jul 2004 01:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:06 AM.