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
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

689 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