Apple Intelligence is now available on iPhone, iPad, and Mac!

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Convert positive to negative value in cells?

Hi,

Can't seem to find this anywhere and Mr Google is starting to refer me to Excel pages, so thought I'd try here - pretty simple, I just want to convert a set of positive values to negative. Is that possible?

Thanks,

osu

Mac OS X (10.6.1)

Posted on Oct 21, 2010 12:04 AM

Reply
7 replies

Oct 21, 2010 12:39 AM in response to onesizeup

If your values are stored in cells of column B, in an other column, say, column C
in cell C2, enter the formula :
=ABS(B2)
then apply Fill Down

If you don't want to use an auxiliary column, use an AppleScript like this one.

--

--[SCRIPT cellstoabs]
(*
Enregistrer le script en tant que Script : cellstoabs.scpt
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Sélectionner un bloc de cellules.
Aller au menu Scripts , choisir Numbers puis choisir cellstoabs
Le script remplace sur place les valeurs négatives par leur valeur absolue.
--=====
L'aide du Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".
Sous 10.6.x,
aller dans le panneau "Général" du dialogue Préférences de l'Éditeur Applescript
puis cocher la case "Afficher le menu des scripts dans la barre des menus".
--=====
Save the script as a Script: cellstoabs.scpt
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
Select a range of cells.
Go to the Scripts Menu, choose Numbers, then choose "cellstoabs"
The script replace the negative values by there ABSolute value.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
Under 10.6.x,
go to the General panel of AppleScript Editor’s Preferences dialog box
and check the “Show Script menu in menu bar” option.
--=====
Yvan KOENIG (VALLAURIS, France)
2010/10/21
*)
--=====
property liste_valeurs : {}
--=====
on run
local dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2, liste_valeurs, c, cc, r, une_valeur
set {dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
if rowNum2 = rowNum1 then set rowNum2 to count of rows
set my liste_valeurs to value of cells rowNum1 thru rowNum2 of columns colNum1 thru colNum2
repeat with c from colNum1 to colNum2
tell column c
set cc to c + 1 - colNum1
repeat with r from rowNum1 to rowNum2
set une_valeur to item (r + 1 - rowNum1) of item cc of my liste_valeurs
if une_valeur < 0 then set value of cell r to -une_valeur
end repeat
end tell
end repeat
end tell
set my liste_valeurs to {}
end run
--=====
(*
set {rowNum1, colNum1, rowNum2, colNum2} to my getCellsAddresses(dname,s_name,t_name,arange)
*)
on getCellsAddresses(d_Name, s_Name, t_Name, r_Name)
local two_Names, row_Num1, col_Num1, row_Num2, col_Num2
tell application "Numbers"
set d_Name to name of document d_Name (* useful if we passed a number *)
tell document d_Name
set s_Name to name of sheet s_Name (* useful if we passed a number *)
tell sheet s_Name
set t_Name to name of table t_Name (* useful if we passed a number *)
end tell -- sheet
end tell -- document
end tell -- Numbers
if r_Name contains ":" then
set two_Names to my decoupe(r_Name, ":")
set {row_Num1, col_Num1} to my decipher(d_Name, s_Name, t_Name, item 1 of two_Names)
if item 2 of two_Names = item 1 of two_Names then
set {row_Num2, col_Num2} to {row_Num1, col_Num1}
else
set {row_Num2, col_Num2} to my decipher(d_Name, s_Name, t_Name, item 2 of two_Names)
end if
else
set {row_Num1, col_Num1} to my decipher(d_Name, s_Name, t_Name, r_Name)
set {row_Num2, col_Num2} to {row_Num1, col_Num1}
end if -- r_Name contains…
return {row_Num1, col_Num1, row_Num2, col_Num2}
end getCellsAddresses
--=====
(*
set { dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
*)
on getSelParams()
local r_Name, t_Name, s_Name, d_Name
set {d_Name, s_Name, t_Name, r_Name} to my getSelection()

if r_Name is missing value then
if my parleAnglais() then
error "No selected cells"
else
error "Il n'y a pas de cellule sélectionnée !"
end if
end if

return {d_Name, s_Name, t_Name, r_Name} & my getCellsAddresses(d_Name, s_Name, t_Name, r_Name)
end getSelParams
--=====
(*
set {rowNumber, columnNumber} to my decipher(docName,sheetName,tableName,cellRef)
apply to named row or named column !
*)
on decipher(d, s, t, n)
tell application "Numbers" to tell document d to tell sheet s to tell table t to ¬
return {address of row of cell n, address of column of cell n}
end decipher
--=====
(*
set { d_Name, s_Name, t_Name, r_Name} to my getSelection()
*)
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum

tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theDoc, theSheet, theTable, theRange}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
on decoupe(t, d)
local oTIDs, l
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
--=====
--[/SCRIPT]
--


Yvan KOENIG (VALLAURIS, France) jeudi 21 octobre 2010 09:38:59

Oct 21, 2010 12:47 AM in response to onesizeup

Placing a negative sign ( - ) in front of a number will reverse its sign. Using ABS() will return the absolute (positive) value of a number.

Original values in column B. Formulas below in column C:

=-B Positive values in B give negative values in C. Negative values in B give positive values in C.

=-ABS(B) Both positive and negative values in B will result in negative values in C.

zero in B gives zero in C with either formula.

The ABS function is discussed on p 170 of the iWork Formulas and Functions User Guide.

Regards,
Barry

Oct 21, 2010 2:24 AM in response to onesizeup

onesizeup wrote:
To Apple: I'm amazed at how ridiculously complicated it is to do something that should be possible in one or two clicks. I find Numbers pretty unintuitive to be honest.


Hi osu,

I'm puzzled by two things:

What would you consider an 'intuitive' method of doing this?

What do you consider 'ridiculously complicated' in using on of the formulas?

Regards,
Barry

Oct 21, 2010 2:50 AM in response to Barry

Hi Barry,

The formulas approach is fine and the one I'll use - I was referring more to the apple script technique. That said, even the formula approach I think has a few too many steps for something that should be a simple 5 second process.

For me, intuitive would be something like a menu command or shortcut for reversing positive values to negative values. Needing to create a new column, type in a formula then cut-n-paste the new negative values into the original column are steps I think could be made more simple, particularly when you have a number of columns and rows with other formulas around it.

Don't get me wrong, I do like Numbers, I just find some things unusual/frustrating - this being one of them.

Regards,

osu

Convert positive to negative value in cells?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.