Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Reverse sign of range

I have a routine that reverses the sign of a list of data. This particularly
useful when entering a list of items and discovering that they're the wrong
way round.

However, it relies on cell A1 being available to create the -1 in the
clipboard.
The drawback with this is that it doesn't work on protected sheets (unless
A1 is unprotected, of course).

Is there a better way of putting -1 into the clipboard ?

Sub Paste_Minus()
' Check that a file is open before attempting to run the procedure
If IsFileOpen() = False Then Exit Sub
' cFormula is the formula contained in cell A1
cFormula = Range("A1").Formula
Range("A1").Value = -1
Range("A1").Copy

Selection.PasteSpecial Paste:=xlValues, Operation:=xlMultiply,
SkipBlanks _
:=False, Transpose:=False

' Return the original formula in A1
Range("A1").Formula = cFormula
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Reverse sign of range

OK - saddo that I am - I've found a workaround to this.

I keep my 'useful functions' in one macro file that I have hidden.
I've placed a range in that file with -1 in it. Copied THAT range and then
proceded as before.

Hey Presto ! Can now reverse the signs of all items in a range with one click.
Sub Paste_Minus()
Workbooks("Other
Macros.xls").Worksheets("Sheet1").Range("Negative_ Calculator").Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlMultiply,
SkipBlanks _
:=False, Transpose:=False

End Sub

Remarkably, it's a lot less code as well.

"Paul" wrote:

I have a routine that reverses the sign of a list of data. This particularly
useful when entering a list of items and discovering that they're the wrong
way round.

However, it relies on cell A1 being available to create the -1 in the
clipboard.
The drawback with this is that it doesn't work on protected sheets (unless
A1 is unprotected, of course).

Is there a better way of putting -1 into the clipboard ?

Sub Paste_Minus()
' Check that a file is open before attempting to run the procedure
If IsFileOpen() = False Then Exit Sub
' cFormula is the formula contained in cell A1
cFormula = Range("A1").Formula
Range("A1").Value = -1
Range("A1").Copy

Selection.PasteSpecial Paste:=xlValues, Operation:=xlMultiply,
SkipBlanks _
:=False, Transpose:=False

' Return the original formula in A1
Range("A1").Formula = cFormula
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Reverse sign of range

Provide your selection is always data (constant numerical values, not
formulas), this is even less code...

Sub ChangeSigns()
Dim Cell As Range
For Each Cell In Selection
Cell.Value = -Cell.Value
Next
End Sub

--
Rick (MVP - Excel)


"Paul" wrote in message
...
OK - saddo that I am - I've found a workaround to this.

I keep my 'useful functions' in one macro file that I have hidden.
I've placed a range in that file with -1 in it. Copied THAT range and
then
proceded as before.

Hey Presto ! Can now reverse the signs of all items in a range with one
click.
Sub Paste_Minus()
Workbooks("Other
Macros.xls").Worksheets("Sheet1").Range("Negative_ Calculator").Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlMultiply,
SkipBlanks _
:=False, Transpose:=False

End Sub

Remarkably, it's a lot less code as well.

"Paul" wrote:

I have a routine that reverses the sign of a list of data. This
particularly
useful when entering a list of items and discovering that they're the
wrong
way round.

However, it relies on cell A1 being available to create the -1 in the
clipboard.
The drawback with this is that it doesn't work on protected sheets
(unless
A1 is unprotected, of course).

Is there a better way of putting -1 into the clipboard ?

Sub Paste_Minus()
' Check that a file is open before attempting to run the procedure
If IsFileOpen() = False Then Exit Sub
' cFormula is the formula contained in cell A1
cFormula = Range("A1").Formula
Range("A1").Value = -1
Range("A1").Copy

Selection.PasteSpecial Paste:=xlValues, Operation:=xlMultiply,
SkipBlanks _
:=False, Transpose:=False

' Return the original formula in A1
Range("A1").Formula = cFormula
End Sub


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 to reverse sign? Chips Excel Worksheet Functions 6 April 10th 12 08:15 PM
In Excel - reverse the sign on a range of numeric cells MaryKaye Excel Discussion (Misc queries) 3 February 18th 10 07:33 PM
Reverse Sign of A Column of Numbers Lee Excel Discussion (Misc queries) 1 March 6th 07 01:58 AM
Function to reverse the sign of a cell epowell74 Excel Worksheet Functions 2 May 19th 05 02:08 PM
Reverse the sign of a number in a cell Peo Sjoblom Excel Worksheet Functions 0 May 17th 05 06:23 PM


All times are GMT +1. The time now is 01:39 AM.

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

About Us

"It's about Microsoft Excel"