LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default How do I assign range to variant and use

I want to work at increasing the speed of macros that work with large
ranges.

I'm told that I can DIM a variable as VARIANT and assign a range to it.
So far so good, but how can that be used? That is, how can maniulate
individual elements in that array (if it's correct to call it an array)?

Here's the stub I'm working with. Note that I'm simply trying to figure
out how these prodcedures work.

The data in A1:E1 is 1,2,3,4,5. I want to change the value 1 to 2 and
write a range of cells back to A2:E2 that looks like 2,2,3,4,5 (so I
know that I actually did something!)

Sub TestVariant

Dim RgArray as Variant
Dim LowBound as Integer, Highbound as Integer
Dim MyArray() As Single

RgArray = Application.Range("A1:E1")
LowBound = LBound(RgArray, 2)
HighBound = UBound(RgArray, 2)

ReDim MyArray(LowBound To HighBound)

'The next statement DOES NOT WORK and produces an error!
'What I'm trying to do is load all the values in RgArray into the local
'array, manipulate the data, and write it back.

MyArray = RgArray 'Does not work

MyArray(1) = 2

'What follows works, but since my array is all zeros at this
'point, except for MyArray(1) (because the MyArray = RgArray
'didn't work), I'm not going to get the result I want. Of course,
'I'm getting 2,0,0,0,0.

RgArray = MyArray
Range ("A2:E2").Value = Rgarray

End Sub

I'm missing something simple but essential here but I can't find it.
What am I missing?

--
Mike H
 
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
I want to assign a value to the letter R in a cell range Poke Excel Worksheet Functions 5 May 15th 07 11:09 PM
Cannot assign a range to seriecollection values matelot Charts and Charting in Excel 3 May 15th 07 03:55 PM
Assign number to correct range blinton25 Excel Discussion (Misc queries) 2 November 17th 06 01:41 PM
Assign number to every value in a data range??? the dude Excel Worksheet Functions 1 May 16th 06 08:41 PM
assign a value to a range travelersway Excel Discussion (Misc queries) 7 November 2nd 05 03:16 PM


All times are GMT +1. The time now is 02:54 PM.

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"