?
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
Medium Priority
?
310 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

801 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