Consulting

Results 1 to 4 of 4

Thread: Solved: Arrays

  1. #1
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location

    Solved: Arrays

    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!!

  2. #2
    VBAX Mentor
    Joined
    Jun 2004
    Posts
    363
    Location
    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.

    [vba]
    sub moveIt
    Dim ary As Range
    Set ary = Range("A1:C7")
    ary.Copy Destination:=Range("a10")
    end sub
    [/vba]
    or something like this - It copies the current selections current region to a location 4 rows below the current region.

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

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Dim ary As Variant
    Set ary = Range("A1:C7")
    Range("A10").Resize(ary.Rows.Count, ary.Columns.Count) = ary.Value[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Thank you both

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •