Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default 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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default 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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default 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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,886
Default 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



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
VLookup returning the sum of multiple values from one "code" Matt Excel Worksheet Functions 4 April 28th 08 01:51 PM
Reverse a "row" of numbers (flip flop them)? wannabe68 New Users to Excel 13 September 22nd 07 07:40 PM
Setting values for "TRUE","FALSE" and "#REF!" Hurtige[_2_] Excel Programming 1 August 11th 06 12:31 PM
Changing "returned" values from "0" to "blank" LATATC Excel Worksheet Functions 2 October 20th 05 04:41 PM
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" Luc[_3_] Excel Programming 2 September 28th 05 08:37 PM


All times are GMT +1. The time now is 10:26 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"