+ Reply to Thread
Results 1 to 40 of 40

Excel macro to pull retrieve data from multiple workbooks in a folder

  1. #1
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Excel macro to pull retrieve data from multiple workbooks in a folder

    Hi ppl,

    i have been trying to find a macro to pull retrieve data from multiple work books from a same folder.

    The criteria is i need to search for a particular string on each workbook sheet(a particular one), the search string could be any where on the work sheet and also some of the cells are merged, if it matches it has to copy the whole row on to a master sheet where it has the first column with file name on it.
    Iam new to VBA Scritping and it is kinda complicated as we have to search a string which can be anywhere on the sheet(row or column not fixed) & also with some of the cells being merged & also there the string searching is repeated.

    Thanks in Advance.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hi Tech,

    Try this:

    Please Login or Register  to view this content.
    The reds need changed to your particularities

    Directions for running the routine(s) just supplied

    Copy the code to the clipboard

    Open your Workbook

    Press ALT + F11 to open the Visual Basic Editor.

    Select "Module" from the Insert menu

    Type "Option Explicit" then paste the code under it

    With the cursor between Sub and End Sub press F5 (F8 to Single Step)

    OR

    Press ALT + Q to close the code window.

    Press ALT + F8 then double click on the macro name
    Last edited by xladept; 03-01-2013 at 08:48 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hi Xladept,

    Thanks for the quick response. i tried to execute the above code sent , iam getting an error which says "The information cannot be pasted because the copy area and the paste area are not the same size and shape. try one of the following 1.click a single cell and then paste 2.select a rectangle that's the same size and shape , and then paste".
    Appreciate your help with it.
    Thanks

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hi Tech,

    Maybe this will allow the paste - if you want to remerge the cells, I'll need to know how many since the new record will start with column B:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hi Xladept,

    when i changed the code to the following iam getting the rows that i need but not getting the file name in the beginning

    Please Login or Register  to view this content.
    it was giving the same error message as earlier. so i changed wm.Cells(r, 2) to wm.Cells(r, 1), it worked but iam not getting the file name in column A.
    Last edited by arlu1201; 03-03-2013 at 02:24 PM. Reason: Code tags and not html tags.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    You're overwriting the file name:

    Try this:

    Please Login or Register  to view this content.
    Last edited by xladept; 03-03-2013 at 02:38 PM.

  7. #7
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Actually i did try with

    Please Login or Register  to view this content.
    it was giving the error message saying "The information cannot be pasted because the copy area and the paste area are not the same size and shape. try one of the following 1.click a single cell and then paste 2.select a rectangle that's the same size and shape , and then paste"

    i changed it to
    Please Login or Register  to view this content.
    just to check if it was working and it did work, so can u please look into it... i need the filename as well.....

    Appreciate your input.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hi Tech,

    We should probably unmerge after the paste - if you need to remerge the cells, I'll need to know how many since the new record will start with column B:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Wow , thank you xladept we are getting close to what is needed.....
    Iam only getting the rows once though i have multiple rows with the same search criteria from a workbook(i do have repeated strings in each workbook and have to copy all of them to the master sheet),and also is it possible to search for multiple search strings....
    Your are great help and infact you are adept.....

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    More than one in a book requires an adjusted Finder routine, multiple search strings? How many strings?

    Probably need a separate finder for each one. I coded the more than one situation recently, I'll look it up and get back to you - we may need to create the multiple search algorithm - so, it would be nice to have a list of those strings

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hi Tech.

    Try this for more than one hit per sheet:

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    iam getting the following error buddy...

    Unable to get the FindNext property of Range class

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Oops! - Try this:

    Please Login or Register  to view this content.
    Last edited by xladept; 03-03-2013 at 11:24 PM.

  14. #14
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Still no luck xladept.... getting the same error message....
    Unable to get the FindNext property of Range class

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Can you post a sample source book?

    Maybe:

    Please Login or Register  to view this content.
    Belay that - I don't need the sample, how about the search string list???
    Last edited by xladept; 03-04-2013 at 01:24 PM.

  16. #16
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    wow man you are goooooooood!!!!!!!!!!
    with regard to multiple search is it possible to search for multiple items instead of just one string(lets say my search strings are "Alpha","Delta","Zeta").
    If it makes it easier(VBA Script) i can add a new sheet with the search strings in Column A(Multiple).

  17. #17
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Would you want the multiple items in order for each sheet and, if so, is there a date column or something that they could be ordered by?? I'll start coding for alpha,beta,zeta - but the more specific the specs....

  18. #18
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    well i can sort it and then search for that string, all matters is filtering the rows which meet the criteria and paste it to a master sheet.
    Thank you for being magnanimous....

  19. #19
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Here's what I have in mind:
    Please Login or Register  to view this content.
    Last edited by xladept; 03-04-2013 at 05:48 PM.

  20. #20
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    it says Cant assign it to an array buddy.

  21. #21
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Quote Originally Posted by xladept View Post
    Would you want the multiple items in order for each sheet and, if so, is there a date column or something that they could be ordered by?? I'll start coding for alpha,beta,zeta - but the more specific the specs....
    Well you are correct i want the data to be in the exact same order & nope i dont have a date column in it to sort the data.
    Last edited by tech_frk; 03-04-2013 at 07:04 PM.

  22. #22
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    See if this gets around it:

    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    its still the same. the message says "compile error: Cant assign to array"

  24. #24
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    That's why the sensei wears a white belt

    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Wow it is working now, is it possible to get the data in the same sequence/order as in the Workbook....

  26. #26
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    That's what the commented out sort is for - how is it ordered in the workbook?? Glad it's working!

  27. #27
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    i have an idea to get the output as needed and that is can we print the row number of the copied one into 1 column and then sort it based on it(we get the same sequence/order as it is found in the workbook).

  28. #28
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    You know what? That's a great idea (and one that I will exploit in the future)!

    Which column - how far do your columns go?

    Please Login or Register  to view this content.
    You can change Columns.Count to N (14)
    Last edited by xladept; 03-05-2013 at 01:45 AM.

  29. #29
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    they go till M column.

  30. #30
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Quote Originally Posted by xladept View Post
    You know what? That's a great idea (and one that I will exploit in the future)!

    Which column - how far do your columns go?

    Please Login or Register  to view this content.
    You can change Columns.Count to N (14)
    Hey buddy, we are almost getting there iam getting an error which says "Method 'Range' of object'_worksheet' failed"
    and it is on the sort part of the code. can you please look into it. Thanks.

  31. #31
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    It ran with this coding - you may want to change to N re IV:

    Please Login or Register  to view this content.

  32. #32
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    In case you need to run it on one of the newer versions, I put the row numbers in O:

    Please Login or Register  to view this content.

  33. #33
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Quote Originally Posted by xladept View Post
    In case you need to run it on one of the newer versions, I put the row numbers in O:

    Please Login or Register  to view this content.
    I Tried this code it is giving the following error:

    This operation requires the merged cells to be identically sized.

    Hitting debug shows the problem on the following code line

    wm.Range("A" & i & ":O" & j).Sort _
    Key1:=wm.Range("O" & i), Order1:=xlAscending, Header:=xlNo
    Last edited by tech_frk; 03-05-2013 at 07:04 PM.

  34. #34
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Please ignore my earlier message, it is working now. let me look into the master list see if this what is needed!!!

    Thank you very much XlAdept you been a big big help buddy.

  35. #35
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    You're welcome! (There shouldn't have been any merged cells???)

  36. #36
    Registered User
    Join Date
    11-02-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: [SOLVED]Excel macro to pull retrieve data from multiple workbooks in a folder

    Successfull!!!!!!!

  37. #37
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hooray! There could have been indexing issues, but it's a done deal

  38. #38
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hi Tech,

    Try this - use the alpha for the special treatment:

    Please Login or Register  to view this content.
    Last edited by xladept; 03-07-2013 at 04:46 PM.

  39. #39
    Registered User
    Join Date
    12-17-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hello, well I tried to follow the thread but as it grew more specific for you guys, it grew to be out of my comprehension. I am attempting to do a similar task.

    I have two, multi-sheet workbooks with thousands of part numbers (14 digit alph-numeric) and various descriptions. I need to combine and in some cases compare them.

    So my first thought was to gather the info into a third, new workbook.
    A macro to go through each workbook (yes they can all be in the same folder.) and search for any cell, on any worksheet, that contains the part numbers (14 digit alph-numeric) starting with "779"

    If a cell contains a part number (14 digit alph-numeric) starting with "779" grab it's contents and the contents of the cell to it's right. Then paste that information into the third, new workbook.

    It would be nice if all the part numbers from a workbook would be placed on one worksheet, and the other workbook's part numbers on the next worksheet.

    Any idea how to do this? It would save me days of work.

  40. #40
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel macro to pull retrieve data from multiple workbooks in a folder

    Hi Fett,

    Start a new thread and I'll see what I can do for you

+ 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