Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Nih
 
Posts: n/a
Default Quick way to change negative #s to positive

Alot of times at work I need to take a column of numbers and change them to
either postive or negative numbers. I would like to be able to select the
cells I want then click a button to change the signs of all the cells I
selected. Is there such a button, like a +/- button?? If not is the fastest
way to do this I can find is to select the cells, hit ctrl H and replace the
- with blank.
  #2   Report Post  
Jason Morin
 
Posts: n/a
Default

I'm not sure if you want to reverse the sign of each number, or simply
convert all numbers to say, positive, even if some already are positive. This
gives you 3 options:

Sub ChangeSign()

Dim cell As Range
Dim rng As Range
Dim iChoice As Integer
Dim strMsg As String

On Error GoTo NoRangeFound
Set rng = Selection.SpecialCells(xlCellTypeConstants, 1)

strMsg = "Type in 1 to convert to all pos., 2 for all neg., or 3 " & _
"to reverse the sign of each value."

iChoice = Application.InputBox(strMsg, , , , , , , 1)

If iChoice < 1 And iChoice < 2 And iChoice < 3 Then
MsgBox "Not a valid number."
Exit Sub
End If

For Each cell In rng
With cell
If iChoice = 1 And .Value < 0 Or _
iChoice = 2 And .Value 0 Or _
iChoice = 3 Then
.Value = .Value * -1
End If
End With
Next
Exit Sub

NoRangeFound:
MsgBox "No numbers found in range!"

End Sub

---
HTH
Jason
Atlanta, GA




"Nih" wrote:

Alot of times at work I need to take a column of numbers and change them to
either postive or negative numbers. I would like to be able to select the
cells I want then click a button to change the signs of all the cells I
selected. Is there such a button, like a +/- button?? If not is the fastest
way to do this I can find is to select the cells, hit ctrl H and replace the
- with blank.

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
Finding negative and positive diffrence Ashish Doshi Excel Worksheet Functions 2 May 24th 05 11:54 PM
how do I rank negative and positive numbers? Anna Excel Worksheet Functions 1 April 6th 05 12:36 AM
How can I change positive numbers to negative, i.e. change 50 to - godwingi Excel Discussion (Misc queries) 5 February 28th 05 05:41 PM
switching values from positive to negative lob Excel Worksheet Functions 5 February 18th 05 11:11 PM
highlighting positive or negative change Dave Excel Discussion (Misc queries) 2 December 27th 04 01:28 PM


All times are GMT +1. The time now is 02:27 AM.

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"