PDA

View Full Version : Solved: Arrays



JKwan
02-08-2010, 12:20 PM
I know arrays are much faster in terms of working / writing to the sheet directly. So, I am trying to work on something simple, but I was not able to figure it out as to how to do it.
so if I have the following code


Dim ary As Variant
ary = Range("A1:C7")

Range("A10") = ary

Range("a10:C16") = ary


- A10 will only get one value of the array - not all!!
- Second Range works - but since the array is varible everytime, I cannot hard code the Range!!

mbarron
02-08-2010, 12:44 PM
What exactly are you trying to do?
If you want to move the information from one spot to another, why not just copy the data.


sub moveIt
Dim ary As Range
Set ary = Range("A1:C7")
ary.Copy Destination:=Range("a10")
end sub

or something like this - It copies the current selections current region to a location 4 rows below the current region.

Sub Move2()
Dim this As Range
Set this = Selection.CurrentRegion
this.Copy Destination:=this.Offset(this.Rows.Count + 4)
End Sub

mdmackillop
02-08-2010, 12:51 PM
Dim ary As Variant
Set ary = Range("A1:C7")
Range("A10").Resize(ary.Rows.Count, ary.Columns.Count) = ary.Value

JKwan
02-08-2010, 06:38 PM
Thank you both