+ Reply to Thread
Results 1 to 16 of 16

Macro to pull data from another file.

  1. #1
    Registered User
    Join Date
    11-18-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    41

    Macro to pull data from another file.

    Hey I am fairly new to programming in excel. I need to create a macro that will go to multiple other spreadsheets (files) and gather certain data (from cells I27, j27, k27) and bring it back to my current spread sheet (and paste to cells c65, d65,e65). For example every day the same spreadsheet is filled out and saved by the date (11-18-10). I need to be able to create a one spreadsheet to copy data from certain cells in each of those sheets and copy them into a yearly spreadsheet with each row as a date and paste into cells c, d, e of that date row. I can use either a button or a GUI. I was trying just to use a button that would go by row and update per date.
    Last edited by eface2face; 11-23-2010 at 03:29 PM. Reason: the problem has been solved

  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: Macro to pull data from another file.

    Hello eface2face,

    Welcome to the Forum!

    I want to make sure I understand you correctly. You want to create a master workbook that contains the information from another workbook named as a date, like 11-18-10.

    Please let me know if any of these assumptions is incorrect.
    1. The information from this workbook is in cells "I27:K27" of each its worksheets.
    2. This information will be copied over to the Master workbook starting with cells "C65:E65" and the next day to cells "C66:E66" etc.
    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
    Registered User
    Join Date
    11-05-2010
    Location
    london, england
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Macro to pull data from another file.

    in the code,

    dim today as date
    dim filename as string
    make "today" automatically change with the date today
    convert today into text "filename"

    open workbook(address\filename)
    activate your current workbook
    call extractdata
    close workbook(address\filename) dont save any changes

  4. #4
    Registered User
    Join Date
    11-05-2010
    Location
    london, england
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Macro to pull data from another file.

    in the sub extractdata(),
    dim address as range
    set address= workbooks("").worksheet("").Range("A!")

    cell(x.x) in your current workbook = address.offset(x,x)

  5. #5
    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: Macro to pull data from another file.

    Hello YellowPower,

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time.

    How to wrap your Code using the # icon
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    To manually wrap your code, use these Bulletin Board Code Tags
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] After the last line.

  6. #6
    Registered User
    Join Date
    11-18-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Macro to pull data from another file.

    Leith

    your assumptions are correct.

    there are multiple workbooks. They are created everyday and are saved by that day's date as 11-18-10, 11-17-10 etc. I need to create a macro that I can use to update my master annual spreadsheet that has the rows listed as the dates. I need to import the data from the individual spreadsheets to the master in the same order you have listed in your reply (individual I27:K27 to the master C65:E65). does that asnwer your questions?


    I have to say that it is hard to explain in words. I hope I didn't make it worse. please let me know.

    Thanks for your help.

  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 pull data from another file.

    Quote Originally Posted by eface2face View Post
    I have to say that it is hard to explain in words. I hope I didn't make it worse. please let me know.
    That's why sample workbooks are the best visual aid. You can post up your master workbook and a couple of your "data" workbooks you want to pull from, then it would be obvious what you want to appear where, yes?

    Click GO ADVANCED and use the paperclip icon to post up a desensitized copy of your workbook.
    _________________
    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!)

  8. #8
    Registered User
    Join Date
    11-18-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Macro to pull data from another file.

    Ok. thanks for the advice.

    The master spreadsheet is where everything needs to be imported from the individual daily sheets. Columns C:E of the master get populated from I26:K26 of the daily sheets. Columns J:L get populated with I16:K16 of the daily logs. Also column G in the master gets populated from L28 of the daliy sheets. Column N in the master sheet gets populated from L29. I hope this will help.


    Master.xls

    10-01-10.xlsx

    10-04-10.xlsx

    10-05-10.xlsx

  9. #9
    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: Macro to pull data from another file.

    Hello eface2face,

    Now that I have downloaded the workbooks, I am confused about what data goes where. Looking at the previous posts nothing matches up. You also have formulae on the "Data" worksheet in the "Master" workbook and there are no column headers. WTF?

  10. #10
    Registered User
    Join Date
    11-18-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Macro to pull data from another file.

    Master(1).xlsx

    10-01-10.xlsx

    10-04-10.xlsx

    I added comments to each sheet. I hope that I explained myself better. Thanks for your help

  11. #11
    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 pull data from another file.

    Give this a try:

    Please Login or Register  to view this content.

    Note the fPath and the fDone strings...

    fPath is the directory where the files are found, remember the final \ in that string

    fDone is where the files are moved to after they are imported so you know they are done. Create that directory if needed.

    Errors are buffered and presented as a list of files that were not processed at the end. Try putting a garbage file in that directory that isn't named for a date and you'll see.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    11-18-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Macro to pull data from another file.

    Jerry

    That code works great. I wanted to know how to stop the macro from deleting the daliy sheets. I ran the macro and the data was copied into the master sheet like it is supposed to, but it deletes the sheet where the data comes from. I need to make sure those daily sheets don't get deleted or consolidated. also how do I change the font of the collected data in the Macro?
    Last edited by eface2face; 11-23-2010 at 02:28 PM.

  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 pull data from another file.

    Did you follow the instructions given in post #11? The macro is looking for an IMPORTED folder inside your data folder, the files are to be moved into there as they are imported to preclude duplicate imports.

  14. #14
    Registered User
    Join Date
    11-18-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Macro to pull data from another file.

    Jerry

    I got it. I changed that file extention and forgot where I was sending the fdone to.

    how do I change the font in the macro or the imported data?

  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 pull data from another file.

    Set the Master sheet columns to the fonts you want, then we'll change the macro to not transfer anything but values.
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    11-18-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Macro to pull data from another file.

    Jerry

    Thank you so much for your help. Sorry that I was a pain in the butt. Next time I will be able to better explain myself. Thanks for spending the time to help me
    Last edited by eface2face; 11-23-2010 at 03:48 PM.

+ 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