![]() |
Most efficient code to "flip" a range of values + vs -
2003/2007
Range("A1").Value = Range("A1").Value * -1 will quickly flip "A1" 9999 to -9999 Let's assume that Set myRange = Range("A1:A3") How does one "flip" the values in myRange? As myRange.Value = myRange.Value * -1 does not work. TIA EagleOne |
Most efficient code to "flip" a range of values + vs -
If you have to resort to code use this:-
Sub marine() Set myrange = Range("A1:A3") For Each c In myrange c.Value = c.Value * -1 Next End Sub But if code can be avoided put -1 in a cell and copy. Select the range to filp and paste special|multiply. Mike " wrote: 2003/2007 Range("A1").Value = Range("A1").Value * -1 will quickly flip "A1" 9999 to -9999 Let's assume that Set myRange = Range("A1:A3") How does one "flip" the values in myRange? As myRange.Value = myRange.Value * -1 does not work. TIA EagleOne |
Most efficient code to "flip" a range of values + vs -
Hi there
you could try something like the code below to iterate through each cell in the range Option Explicit Dim MyCell, MyRng As Range Private Sub CommandButton1_Click() Set MyRng = [A1:A3] For Each MyCell In MyRng MyCell.Value = MyCell.Value * -1 Next MyCell End Sub Hope this helps S |
Most efficient code to "flip" a range of values + vs -
Mike, I can not use the -1 in the CopyTo Cells PasteSpecial/Multiply option.
The For Next works fine. Thanks Any thoughts about initializng, multipling, pasting an array? Mike H <M wrote: If you have to resort to code use this:- Sub marine() Set myrange = Range("A1:A3") For Each c In myrange c.Value = c.Value * -1 Next End Sub But if code can be avoided put -1 in a cell and copy. Select the range to filp and paste special|multiply. Mike " wrote: 2003/2007 Range("A1").Value = Range("A1").Value * -1 will quickly flip "A1" 9999 to -9999 Let's assume that Set myRange = Range("A1:A3") How does one "flip" the values in myRange? As myRange.Value = myRange.Value * -1 does not work. TIA EagleOne |
Most efficient code to "flip" a range of values + vs -
Look at PasteSpecial, values & multiply
Start by copying a cell that contains -1 Record a macro Regards, Peter T wrote in message ... 2003/2007 Range("A1").Value = Range("A1").Value * -1 will quickly flip "A1" 9999 to -9999 Let's assume that Set myRange = Range("A1:A3") How does one "flip" the values in myRange? As myRange.Value = myRange.Value * -1 does not work. TIA EagleOne |
Most efficient code to "flip" a range of values + vs -
How does one "flip" the values in myRange?
As myRange.Value = myRange.Value * -1 does not work. Hi. To do it without a loop requires a slightly different technique: Sub Demo() [A1:A10] = [- A1:A10] End Sub -- HTH :) Dana DeLouis Windows XP & Excel 2007 wrote in message ... 2003/2007 Range("A1").Value = Range("A1").Value * -1 will quickly flip "A1" 9999 to -9999 Let's assume that Set myRange = Range("A1:A3") How does one "flip" the values in myRange? As myRange.Value = myRange.Value * -1 does not work. TIA EagleOne |
Most efficient code to "flip" a range of values + vs -
Dana,
is [A1:A10] = [- A1:A10] an Array usage in VBA? EagleOne "Dana DeLouis" wrote: How does one "flip" the values in myRange? As myRange.Value = myRange.Value * -1 does not work. Hi. To do it without a loop requires a slightly different technique: Sub Demo() [A1:A10] = [- A1:A10] End Sub |
Most efficient code to "flip" a range of values + vs -
Dana,
Can one get a variable into the [ ]? I attempted: [myRange] = [- myRange] then [myRange.address] = [- myRange.address] then x = myRange.address [x] = [- x] to no avail. "Dana DeLouis" wrote: How does one "flip" the values in myRange? As myRange.Value = myRange.Value * -1 does not work. Hi. To do it without a loop requires a slightly different technique: Sub Demo() [A1:A10] = [- A1:A10] End Sub |
Most efficient code to "flip" a range of values + vs -
Hi
Sub test() [myrange] = [-myrange] End Sub worked fine for me in XL2003 and XL2007 -- Regards Roger Govier wrote in message ... Dana, Can one get a variable into the [ ]? I attempted: [myRange] = [- myRange] then [myRange.address] = [- myRange.address] then x = myRange.address [x] = [- x] to no avail. "Dana DeLouis" wrote: How does one "flip" the values in myRange? As myRange.Value = myRange.Value * -1 does not work. Hi. To do it without a loop requires a slightly different technique: Sub Demo() [A1:A10] = [- A1:A10] End Sub |
All times are GMT +1. The time now is 02:04 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com