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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

This article will show you how to use shortcut menus in the Access run-time environment.
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now