+ Reply to Thread
Results 1 to 30 of 30

line item extractor

  1. #1
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    line item extractor

    Ok, so here is the deal. I have multiple excel files with 20-30 sheets per file. These files are full of data, account numbers etc etc. I have been trying to build a macro that can crawl through every sheet and extract line item. For example, in the attached worksheet, if i want to extract the rows for account number 251122812 from all sheets, and put it in a new file or maybe a sheet within the main file, how can i do it? Please help me out, there are thousands of line items that need to be extracted, and its simply a tedious work to do it manually....

    Any help will be appreciated and remembered
    Attached Files Attached Files
    Last edited by bholabhala; 05-16-2010 at 03:21 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    We need to clarify what you're really after.

    1) Do you want to create new worksheet for all items matching single account number?

    2) If yes, is this worksheet in a new master workbook or inside one of your many workbooks?

    3) Are we consolidating the info in all sheets in ONE workbook (already open) or do you want to sift through an entire folder on your hard drive and pull in all the data for a single account number?

    4) If sifting through an entire folder, your data does not include dates or any identifying information. Would you need to add the workbook name and/or sheet name each bit of data came from, or no?

    ===============
    I would think possibly something like this:

    1) In a Master workbook, prompt user to enter an account number
    2) If a worksheet already exists for that account number, clear the sheet and get ready to enter new data, if not then create this new sheet
    3) Prompt user to select a folder to sift through all files
    4) After folder is selected open each file one at a time
    5) In each file opened, cycle through ALL sheets and filter for data in column A matching the account number, copy it to the Master-Acct # sheet adding workbook names and sheet names to each row of copied data.

    Is that about right?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    1) Yes, i wants all the lines extracted from allt he sheets, withint a workbook to be put in a new workbook, and not in another sheet, within the original workbook

    2) A new master workbook

    3) Crawling through entire folder is not necessary. All the sheets, within one book needs to be crawled and all the lines for a specific account number to be extracted and put in a new master workbook.

    4) Well, the new workbook can be named after the account number. That will eb awesome

    You are so kind and helpful. I really appreciate all the help

    ------------------------------------------------------------------------------
    ------------------------------------------------------------------------------

    Regarding the second part. There are hundereds of workbooks that need to be crawled. Each workbook has 10-30 sheets. The speicif loan number is found only in one workbook and no other workbook. If something like this can be created, where user can enter loan number and the macro will crawl the whole workbook and every sheet within that workbook, extract the whole line and put all the extracted lines in a new workbook, it will be awesome..


    Thanks again

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    Got a sample workbook with the exact layout and a good set of sample data?

    Click GO ADVANCED and use the paperclip icon to post up your workbook.

  5. #5
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    First thing i will do, after i get home, is to attach a 3 sheet test workbook for you.

    Again, i appreciate the help

  6. #6
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    I have attached a test workbook for you.
    Attached Files Attached Files

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    Last question, will the workbook to search already be open? I envision the beginning of the macro prompting you to enter an Account number, then prompting you to select a workbook from the hard drive. The macro opens the wb, pulls all the data, closes that workbook, then saves this new wb and leaves it open for you to review.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    Put this into an empty workbook to run from, it won't be in the workbook created, nor needs to be in the workbooks being searched.
    Please Login or Register  to view this content.

    If you already have the workbook open that you want to search/consolidate, then click on the account number and run the macro. Whatever the Activecell is will be used to offer you an account number verification, just press ENTER to accept it and YES to confirm this is the workbook you want to search.

    If this ISN'T the workbook, just enter the correct Account Number and then say NO to the workbook question, it will let you select another workbook.

    The workbook created will be saved with the account number and the current date.


    This is based on the macro ConsolidateSheets from my site here:
    Last edited by JBeaucaire; 05-08-2010 at 03:52 PM. Reason: Fixed error in AcctCol search code

  9. #9
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    BTW, where am i supposed to put this code? Like in a cell ?

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    How/Where to install the macro:

    1. Open a new Empty workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save as a macro-enabled workbook

    The macro is installed and ready to use.

    ===========
    How to use the macro:

    1) With this workbook open, enter an account number into a cell and click it to make sure it is the active cell
    2) Press Alt-F8 and select ConsolidateInfoFromSheets from the macro list.
    3) Confirm this the account number you want, or enter a new one in the popup and press OK
    4) If the current active workbook is not the workbook to search, click NO and select the workbook from your harddrive

  11. #11
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    THe script is awesome. I am so glad i am getting help from you. there is a problem though. When i enter accoutn number and press 'OK', it asks me to add workbooks, i search for workbook and then press OK. i get error code 91.


    Runtime error 91

    After Debugging:This section is highlighted in Yellow

    Please Login or Register  to view this content.
    Last edited by bholabhala; 05-09-2010 at 03:02 PM.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro to extract line specific line item from Excel Sheets

    Please edit your post to add CODE tags.
    Entia non sunt multiplicanda sine necessitate

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    In my signature is an example of the
    Please Login or Register  to view this content.
    [/noparse]
    tags you need to put around the code you posted above. EDIT your prior post and add them. The result will look like my post #8.

  14. #14
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    ok, i've done it. Sorry abt that

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    The hidden sheet SQL-SETTINGS caused a hiccup. I corrected the code above in post #8 (added a ws reference to help overcome the problem. I tested it an it's working now. Try it again.

  16. #16
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    Ok, i tried it again, this time, the error is different though. Error code is still 91, but the statement is different. I have attached a screen shot of the error code.

    Thanks for all your assistance.
    Attached Images Attached Images

  17. #17
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    And when you debug, which line of code is highlighted?

  18. #18
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    Please Login or Register  to view this content.

  19. #19
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    That line of code is the macro trying to spot the "Account Number" string on the currently evaluated sheet. It should simply fail and move on, which it does on the visible sheets. I still think you're getting hung up on the hidden worksheet, though it isn't doing that for me.

    Maybe add this:
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    OMG
    This code works like charm. I just wanna let you know that you are an angel

    Thank you so so so so so much for your help, and without a returun. Thats a true nobility.

    How can i rate you? And write a review for what you've done for me ?

  21. #21
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

    There's a scales icon in my posts you can use for a reputation feedback.

    And you can visit my site for more code excerpts. This macro for you was based on code from there, the link is in my signature.

  22. #22
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    one more issue.. last one, i promise. Its kinda putting the sheets in reverse order. The first sheet is appearing at the end

    Any way to fix that?

  23. #23
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    Can you post the full macro again so we can see it in it's current complexity?

  24. #24
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    Please Login or Register  to view this content.

  25. #25
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    Odd, that looks like the original macro. I don't see any changes, including the one you got from post #19.

    The macro is collecting data going through the worksheets in the workbook one at a time. It's simply using the order of sheets that you have.

  26. #26
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: Macro to extract line specific line item from Excel Sheets

    makes sense. Is there any possible way to reverse that crawl? the reason is that i will have to change the order of hundereds of sheets and that will be a big pain ....

  27. #27
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract line specific line item from Excel Sheets

    Try this:
    Please Login or Register  to view this content.

  28. #28
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: line item extractor

    Ok i am back. The macro works perfectly and everything, but there is a slight problem.
    The account numbers, starting with zero's get ignored by the macro. Any way to enable macro to extract these account numbers too?

    Thank you for all your support

  29. #29
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: line item extractor

    Account numbers cannot start with zero without first converting those cells to text....which goes against the idea of an account "number", eh?

    Convert your account numbers to actual numbers, then use cell formatting to "display" leading zeros if you really feel you need to see them. Then the macro should work fine as designed.

  30. #30
    Registered User
    Join Date
    03-06-2004
    Posts
    53

    Re: line item extractor

    makes sense. I appreciate it...

+ 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