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
271 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will show you how to use shortcut menus in the Access run-time environment.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

743 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

17 Experts available now in Live!

Get 1:1 Help Now