+ Reply to Thread
Results 1 to 7 of 7

Extract information from 2nd workbook and record in current workbook. VBA

  1. #1
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Extract information from 2nd workbook and record in current workbook. VBA

    Hi there,

    I am trying to come up with a macro that will ideally help me find information easily. I have attached two workbooks.

    The Current File DIS is the file where the macro should go, and the Master Transfer file is the file to extract information from.

    What I would like to do:

    1) Search each record found in the Current File DIS against the Master Transfer file and find matches.
    2) If a match is found, (matching conditions are matching MRN and ADM_Date), have the macro record what happened to that patient based on the Master Transfer File in the "transfers Details" column.

    For example, if a matching record is found, I would want this macro to extract what's in the "eff_date, PCU out and PCU in" from the Master Transfer file and record all of that in the "Transfers Details" column for THAT patient. I have put some dummy records in the "Current file" for illustration. Both 12345 and 74463 are patients found in the "master transfer" file. The "Transfer Details" comes from the "master transfer file".

    If no matching record found, move on. (no transfers for that patient), or just put "None" in the "Transfer Details".

    The difficulty for me is putting what can be multiple lines of info into a single cell.

    Is anybody able to assist me on this one?

    Thanks very much
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract information from 2nd workbook and record in current workbook. VBA

    Anybody able to assist?

  3. #3
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract information from 2nd workbook and record in current workbook. VBA

    anyone able to assist?

    Thanks

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Extract information from 2nd workbook and record in current workbook. VBA

    Lifeseeker, try this.

    Make sure you edit the workbook path for "Master Transfers" in the code.
    Attached Files Attached Files
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  5. #5
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract information from 2nd workbook and record in current workbook. VBA

    Nice....I tested it and it worked!

    So what's in the Find() are pretty much all standard parameter settings in my example?

    and am I correct for understanding this logic?
    In the Find() code segments, this is where we first find the matching MRN. Then, if the matching MRN has been identified, we look for matching adm_date, which is that big If statement. Correct?

    Thanks

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Extract information from 2nd workbook and record in current workbook. VBA

    The find is configured so it will find the first match in the column and due to each patient having two rows of data you want to keep it that way, b/c as you said the next part of the code matches the adm-date and parse the relevant info all based off the found cell. If "Current File DIS" has thousands of entries, the code may need to updated and perform this via an array.

  7. #7
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract information from 2nd workbook and record in current workbook. VBA

    Not every patient has a maximum of 2 rows. They could have up to 10 rows, depending on how many transfers they have over a period of time.

    I think this doesn't matter right? The code looks for, in the found cells, all the necessary informations.

+ 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