+ Reply to Thread
Results 1 to 23 of 23

How to extract data via a macro from multiple workbooks?

  1. #1
    Registered User
    Join Date
    09-12-2012
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    9

    How to extract data via a macro from multiple workbooks?

    Hi everyone!

    I am new to the Forum, but I have a sticky issue. I have about 500 excel files that contain some data elements that I need to extract and insert into a master workbook. Using VBA I would like to call the individual workbooks and get the information from the specific cells. The cell reference will be the same in all the workbooks but each workbook has a different name (i.e Workbook names are: John.Smith.xlsm, Jane.Smith.xlms, James.Smith.xlms and in each workbook is data in cell reference (12,3) that I would like to have input in the master workbook.) Is this possible?
    Last edited by lross318; 09-12-2012 at 10:52 PM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    Sure its possible. So only M12 in each file that should be extracted into the master file?

    Should the data be input one below the other? Do you want the name of the file to be input into the master file as well?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    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,445

    Re: How to extract data via a macro from multiple workbooks?

    @Arlette: M12? I think it would be L3 or C12 depending on the way the co-ordinates are interpreted.

    Cells(12,3) would be C12.

    Regards, TMS
    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


  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    My bad TMS. I saw it as 12,13. Yes, it should be C12.

  5. #5
    Registered User
    Join Date
    09-12-2012
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to extract data via a macro from multiple workbooks?

    Yes, C12 is the only thing that needs to be extracted from each file and the data should be one below the other. So in the master file C2 = Smith D2 = John J2 is where I want the macro to insert the data from the other excel file, for John.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    Do you want the filename to be inserted along with the value from C12 of each file?

  7. #7
    Registered User
    Join Date
    09-12-2012
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to extract data via a macro from multiple workbooks?

    Yes, but that should be in the next column

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    Try this code
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  9. #9
    Registered User
    Join Date
    09-12-2012
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to extract data via a macro from multiple workbooks?

    Thank you! This is really helpful! If I understand the code and variables correctly, I should replace {myPath = "D:\Test"} with mypath = {the directory of the excel files} is that true?

    Thanks so much!
    LRoss

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    Yes you are right.

  11. #11
    Registered User
    Join Date
    09-15-2012
    Location
    Trichy
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How to extract data via a macro from multiple workbooks?

    Hi

    i tried this and its working good. i am in the same position as lross318. I am having set of excel sheet in a single folder. The datas in the excel will change every month in the same cell. We took those values and paste it in another table. But this macro stored the exact values in the exact position of the master sheet. Did you have any idea to store those values in the some other cell of the master sheet.

  12. #12
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How to extract data via a macro from multiple workbooks?

    Hello mouli51188, and welcome to the forum.

    Unfortunately you have inadvertently broken one of the forum rules. Please read the following and make the necessary change. Thanks.

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

  13. #13
    Registered User
    Join Date
    09-15-2012
    Location
    Trichy
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How to extract data via a macro from multiple workbooks?

    Hi ,

    Sorry for violating forum rules. wont do the same in future. Kindly chk the below thread for my queries

    http://www.excelforum.com/excel-prog...her-excel.html

  14. #14
    Registered User
    Join Date
    09-12-2012
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to extract data via a macro from multiple workbooks?

    When I try to run the code I get a Debug error at {Workbooks.Open (myPath & "\" & CurrentFileName)}. Any thoughts?

  15. #15
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    What is the error number / description?

  16. #16
    Registered User
    Join Date
    09-12-2012
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to extract data via a macro from multiple workbooks?

    Run-time Error '1004'

    'C:\test\*xmls' could not be found.

    But I put the files in a test folder on the C drive, so I am a little confused.

  17. #17
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    What is the file extension of all the files?

  18. #18
    Registered User
    Join Date
    09-12-2012
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to extract data via a macro from multiple workbooks?

    Actually I see, what that error was, but now I get a Run time error number 52 Bad file name or number

  19. #19
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    What is the file extension?

  20. #20
    Registered User
    Join Date
    09-12-2012
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to extract data via a macro from multiple workbooks?

    All the files are .xlsm.

    So my C:\test folder worked but I am wondering if I am getting an error because the files live on a secure shared server.

  21. #21
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    I am not sure about the secure share drive, but change this line from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    09-12-2012
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to extract data via a macro from multiple workbooks?

    OK. I did that.

    Here is where I am getting the runtime error 52 (Bad file name):

    CurrentFileName = Dir(myPath & "*.xlsm")

    It is as if the code is not recognising that the "*" is a wild card.

  23. #23
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to extract data via a macro from multiple workbooks?

    That line should be CurrentFileName = Dir(myPath & "\*.xlsm")

+ 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