Solved

How do I use arrays in VBA to cut a massive amount of data from one sheet to the next

Posted on 2011-03-14
3
287 Views
Last Modified: 2012-05-11
Hi
I need to loop through a large amount of data in one sheet and cut and paste a subset of it into another sheet.  Currently I'm using a For Next loop to cut and paste individual rows of data, but it's very slow.
I would like to either copy all rows in one go to an array, and then paste it to the new sheet, or else copy to virtual memory, if that's at all possible.
Regards
JL
0
Comment
Question by:jlfourie
  • 2
3 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 35129273
How about filtering the data on the original sheet, and copying the filtered range only to a new sheet?

Adding a template workbook would probably improve the quality of the input you will get.

Thoma
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35129342
Dim arr As Variant

    arr = Sheets("Sheet1").Range("A1:D5")
    Sheets(2).Range("a1:d5") = arr

Or whatever range you want.  Be warned the array has two dimensions as row then column.

Chris
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 35129448
To give an example of an iterating loop see the snippet

I have used blocks of 40 datums but whilst not infinite much greater blocks can be used

Chris
Dim arr As Variant
Dim rng As Range
Dim lngRow As Long

    For lngRow = 0 To 100 Step 10
        Set rng = Sheets("Sheet1").Range("A" & lngRow + 1 & ":D" & lngRow + 10)
        Debug.Print rng.Address
        arr = rng
        Sheets(2).Range(rng.Address).Formula = arr
    Next

Open in new window

0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question