Negative to Positive

stumps

New Member
Joined
Jan 26, 2018
Messages
22
Hi Forum

I would like to change a few cells that appear as negative numbers to positive numbers.
 
Or simply =ABS(A2) .

But IMHO, "stumps's" request is unclear. For starters, does column A (or whatever) contain constants or formulas? Does "stump" merely want to change how the values "appear"?


Spreadsheet 1 has column A who's cells contain formulas, the cells totals add up and are placed in a single cell which is a negative number
i.e. cells A3:A99 all have formulas with negative totals, that is placed in cell A100 - formula in cell A100 : = sum(A3:A99)

In Spreadsheet 2 the total of cell A100 is placed into cell B1 : =Spreadsheet 1!A100 - would like to have this number to change into a positive
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Since I am learning VBA, I was trying to make a macro to convert all the negative number into positive numbers but due to some reason it doesn't work. The VBA seems to reject my IF statements.

Experts' assistance required.

Code:
Sub positive()

Dim r As Range
Dim c As Integer


Set r = Selection


[COLOR=#ff0000]    For Each c In r[/COLOR]
[COLOR=#ff0000]        If c.value < 0[/COLOR]
        Then c.value =  c * -1
        Else
        x
    End If
    Next


End Sub
Why do you even need the Else statement as you are already testing for only cells with the negative?
Rich (BB code):
Sub positive()

Dim r As Range, c As Range

Set r = Selection

For Each c In r
If c.Value < 0 Then c.Value = c.Value * -1
Next

End Sub

Back to the question...

Spreadsheet 1 has column A who's cells contain formulas, the cells totals add up and are placed in a single cell which is a negative number
i.e. cells A3:A99 all have formulas with negative totals, that is placed in cell A100 - formula in cell A100 : = sum(A3:A99)

In Spreadsheet 2 the total of cell A100 is placed into cell B1 : =Spreadsheet 1!A100 - would like to have this number to change into a positive

Does ABS that joeu2004 posted not work? i.e.
=ABS(Spreadsheet 1!A100)
 
Last edited:
Upvote 0
thanks for the code MARK, but would you please tell me why the code gets stuck there on the if statement? i changed the code a bit to include a Else condition . Still it didn't work.
Code:
Sub positive()Dim r As Range
Dim c As Range
Set r = Selection
    For Each c In r
        If c.value < 0
        Then c.value = c.value * -1
        Else
        c.Value = c.Value * -2
    End If
    Next
End Sub
 
Upvote 0
The code I posted works for me as long as I have made a selection.
In the code you have posted you have the "Then" on the wrong line.

and why do you need the Else statement as the OP didn't request the other cells to be altered?
 
Upvote 0
thanks for the code MARK, but would you please tell me why the code gets stuck there on the if statement? i changed the code a bit to include a Else condition . Still it didn't work.
Code:
Sub positive()Dim r As Range
Dim c As Range
Set r = Selection
    For Each c In r
        [B][COLOR="#FF0000"]If[/COLOR][/B] c.value < 0
        [B][COLOR="#FF0000"]Then[/COLOR][/B] c.value = c.value * -1
        Else
        c.Value = c.Value * -2
    End If
    Next
End Sub
The Then keyword must be on the same line as the If keyword...
Code:
Sub positive()Dim r As Range
Dim c As Range
Set r = Selection
    For Each c In r
        If c.value < 0 Then
            c.value = c.value * -1
        Else
            c.Value = c.Value * -2
        End If
    Next
End Sub
 
Upvote 0
OMG, what a silly mistake

The re positioning of "Then" did the trick.

Also, I am sorry to go a bit off-topic from OP's question here.
 
Upvote 0
Spreadsheet 1 [....] cells A3:A99 all have formulas with negative totals, that is placed in cell A100 - formula in cell A100 : = sum(A3:A99)[.] In Spreadsheet 2 the total of cell A100 is placed into cell B1 : =Spreadsheet 1!A100 - would like to have this number to change into a positive

If you know that A100 is always negative, then:

=-'Spreadsheet 1'!A100

If A100 may or may not be negative, then:

=ABS('Spreadsheet 1'!A100)
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top