+ Reply to Thread
Results 1 to 8 of 8

Selecting Multiple Data Ranges

  1. #1
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Selecting Multiple Data Ranges

    I built the following macro to help me pull 22,000+ rows of data from a spreadsheet that I get every Monday:

    For ease of reading, Ill break it down into steps:

    Step 1 - Renames the existing sheet to "852", adds a second sheet called "Dump", & creates headers for columns A:K in row 1.


    Please Login or Register  to view this content.

    Step 2 - Take data from column B row 13 to the last row of data in B based on column A and pasts it to "Dump" starting in C2:

    Please Login or Register  to view this content.
    Step 3, 4, & 5 - Similar to Step 2 except they are applied to and pasted in:

    column D into "Dump" A2
    column G into "Dump" H2
    column H into "Dump" K2

    Again you will see that I am selecting data from column (D,G or H) row 13 to the last row of data in B based on column A:

    Please Login or Register  to view this content.

    I feel like there is a more efficient way to code this so that steps 2 through 5 copy the respective data and then pastes in into the new sheet.

    If it makes things easier I can have the data pasted in columns A through D on the Dump sheet.

    Thanks!

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Selecting Multiple Data Ranges

    You need some type of looping in your code. I'm old fashion so I like the For..Next loop. You can then use the Choose() function to tell which columns are being copied and again for where they will be pasted. I'm sure there is a lot cleaner code but this will get close to working. Note that Column "B" is replaced by 2 and ect.

    Please Login or Register  to view this content.
    Last edited by MarvinP; 07-28-2010 at 12:59 AM.

  3. #3
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151

    Re: Selecting Multiple Data Ranges

    Or maybe something like:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Selecting Multiple Data Ranges

    The most important thing is to not select any sheets or ranges, doing so will slow your code.

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Selecting Multiple Data Ranges

    The most important thing is to not select any sheets or ranges, doing so will slow your code.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: Selecting Multiple Data Ranges

    MarvinP,

    Many thanks for condensing this down for me.

    For some reason your code is not working. I keep getting a "Compile Error: Invalid or unqualified reference" and it highlights on ".Rows" in the line of code:

    Please Login or Register  to view this content.
    The code that Roy & Shred provided are working but I thought you would like to know.

    Thanks again!!

  7. #7
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: Selecting Multiple Data Ranges

    RoyUK & ShredDude,

    Thank you very much for the codes you provided. I ran both and came out with the same (excellent) result. Pats on the back for all of you (You too MarvinP)...

    It never ceases to amaze me how many different ways you can code to get the same result.

    Two questions....

    You both use (in one form or another) the following code to copy and paste:

    Roy's Code:

    Please Login or Register  to view this content.

    Shred's Code:

    Please Login or Register  to view this content.

    I see what the line of code does but I don't understand how the paste function execute.

    Second question...

    Can the data be pasted simply as value and not with the format?

    Thanks.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Selecting Multiple Data Ranges

    Try this slightly amended code
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1