+ Reply to Thread
Results 1 to 6 of 6

Retrieve data from specific sheets

  1. #1
    Registered User
    Join Date
    01-19-2011
    Location
    Romania
    MS-Off Ver
    Excel 2003
    Posts
    7

    Retrieve data from specific sheets

    Hello!
    This is my fist post here and I'm rather new to Excel, so I'll probably cause a lot of laughs. Here is the matter:

    I have a file with 50+ sheets, of which 45 are named nr1, nr2, nr3... nr(still growing). I need to collect all the data in the first column of each sheet that starts with "nrX" and add it into the Xth column of a different sheet (1st column of 1st sheet to 1st column, 1st column of 2nd sheet into 2nd column etc.). The data in those cells is text. The problem is that my lame script only reads the first sheet. Here is what I have so far:

    Please Login or Register  to view this content.
    I added the msgbox only to see which sheet actually gets read, if you're wondering why it's there. I can't seem to make it work past the first sheet.
    Last edited by danj; 01-19-2011 at 03:53 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Retrieve data from specific sheets

    Hello danj,

    Welcome to the Forum!

    Try this version of your macro.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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

    Re: Retrieve data from specific sheets

    Hi danj and welcome to the forum.

    Try this code which is in the attached.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    01-19-2011
    Location
    Romania
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Retrieve data from specific sheets

    Hello and many thanks on your quick reply!
    Here is the quick result:
    1. sh was double defined and had to remove one instance
    2. it only brings me the first cell in each column, not the whole column

    EDIT> Sorry, it was working, you are indeed masterful at this :-)

    EDIT 2> Actually, it was Marvin's stuff that was working, but many thanks to both of you!
    Last edited by danj; 01-19-2011 at 04:00 PM.

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

    Re: Retrieve data from specific sheets

    I'm not sure Leith knows what sheet number it is using.
    That is if you have nr1, nr2 and no 3 or 4 but nr5 next he might not put the result on sumar on the correct number column.

    Test my code to see if it is what you want.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Retrieve data from specific sheets

    You could also do this with a formula.

    With nr1, nr2, nr3, etc in cells A1 to AZ1, whatever, in cell A2:

    =IF(ISERROR(INDIRECT(A$1&"!A"&ROW($A2))),"",INDIRECT(A$1&"!A"&ROW($A2)))&""

    Drag down and across.

    Copy and paste special values to remove the formulae.

    You could, of course, use VBA to populate the cells and then convert to values but I guess you have several VBA approaches already ;-)

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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