+ Reply to Thread
Results 1 to 15 of 15

VBA Code to Pull out the data from the closed workbook

  1. #1
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    VBA Code to Pull out the data from the closed workbook

    Hello Everyone,

    I need to fetch out the data basis on some criteria's from the closed workbook. As I know it's possible only through VBA code. Explaining with an example;

    Pull out the data in "Sheet1", Column D basis on criteria's in Column A, B & C from "Sheet2" (multiple tabs). Hope I'm able to explain. Can anyone in the forum please help me out. I am scratching my head from the morning but not been able to resolve it. Attaching the sheets for your reference.

    Many Thanks in Advance.

    Best Regards,
    Abhishek
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: VBA Code to Pull out the data from the closed workbook

    Hello, this does not require VBA.

    Menu Bar > Data > Get External Data > From Other Sources > From Microsoft Query > Excel Files* > Paste path to excel file into "Database name" field, hit Enter > Select the Excel file you wish to query from.

  3. #3
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: VBA Code to Pull out the data from the closed workbook

    If you have the both sheets on same folder then write the following array formula on cell D2 of Sheet1 and copy it down. That's it.
    Please Login or Register  to view this content.
    To confirm an array formula press Ctrl+Shift+Enter.

    If you have that Sheet2 on different folder then change each "[Sheet2.xlsx]"&$A2&"! to "'C:\Users\user\Desktop\[Sheet2.xlsx]"&$A2&"'! on above formula, where replace C:\Users\user\Desktop\ with the address of Sheet2.

  4. #4
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: VBA Code to Pull out the data from the closed workbook

    Thanks Sanram for the response. The formula is working fine when the Sheet2 is open. But actually in my case Sheet2 is closed. Is there any way that I can do the same thing when the Sheet2 is closed.

    Best Regards,
    Abhishek

  5. #5
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: VBA Code to Pull out the data from the closed workbook

    Thanks Poizhan for the response. I tired using the method you mentioned but getting an error as "This data source contains no visible tables". No idea if I am doing something wrong. Could you please elaborate by using the same in sample attached files. Thanks.

    Best Regards,
    Abhishek

  6. #6
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: VBA Code to Pull out the data from the closed workbook

    Quote Originally Posted by abhi_jain80 View Post
    Thanks Sanram for the response. The formula is working fine when the Sheet2 is open. But actually in my case Sheet2 is closed. Is there any way that I can do the same thing when the Sheet2 is closed.

    Best Regards,
    Abhishek
    This formula will work all the time. To get the updated data from the formula press F9. That's it.

  7. #7
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: VBA Code to Pull out the data from the closed workbook

    It the Sheet2 is closed, the formula is not working. The error coming as #REF!...If I open up Sheet2, the values appears. No idea if I am doing anything wrong or might Indirect function won't work on closed workbooks.

    Best Regards,
    Abhishek

  8. #8
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: VBA Code to Pull out the data from the closed workbook

    Quote Originally Posted by abhi_jain80 View Post
    It the Sheet2 is closed, the formula is not working. The error coming as #REF!...If I open up Sheet2, the values appears. No idea if I am doing anything wrong or might Indirect function won't work on closed workbooks.

    Best Regards,
    Abhishek

    #REF! means the address of sheet2 file is wrong. Please check that.

  9. #9
    Banned User!
    Join Date
    10-29-2012
    Location
    Europe
    MS-Off Ver
    2013, 2016
    Posts
    318

    Re: VBA Code to Pull out the data from the closed workbook

    Quote Originally Posted by sanram View Post
    #REF! means the address of sheet2 file is wrong. Please check that.

    @sanram,

    INDIRECT won't work with closed file.

  10. #10
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Re: VBA Code to Pull out the data from the closed workbook

    Quote Originally Posted by Indi_Ra View Post
    @sanram,

    INDIRECT won't work with closed file.
    Is there any other option to resolve the issue.

  11. #11
    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: VBA Code to Pull out the data from the closed workbook

    Hello abhi_jain80,

    This can be done in two ways using macros. The easiest is to open the workbook, read in the data, and then close the workbook. The other method would be to use ADO. This option is quite complex and not really any faster than the first method.

    The code below opens the workbook, reads in the data, and then closes it. A button has been added to the "Data" sheet to run the macro. Each time the macro runs the old data is cleared.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    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!)

  12. #12
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: VBA Code to Pull out the data from the closed workbook

    Quote Originally Posted by Indi_Ra View Post
    @sanram,

    INDIRECT won't work with closed file.
    Thanks for the info. I didn't know that before.

  13. #13
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: VBA Code to Pull out the data from the closed workbook

    Quote Originally Posted by abhi_jain80 View Post
    Is there any other option to resolve the issue.
    In your case you can use the following code

    Please Login or Register  to view this content.
    Here Replace C:\Users\Surith\Downloads\ with the address of your Sheet2.

    This code will create a linked formula on the respective cell of column D whenever you type a new value in column A.
    Last edited by sanram; 08-13-2016 at 09:33 PM.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,681

    Re: VBA Code to Pull out the data from the closed workbook

    Try
    Please Login or Register  to view this content.
    Alter "1000" to site.

  15. #15
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    Thumbs up Re: VBA Code to Pull out the data from the closed workbook

    The solutions you provided is absolutely working fine. Thanks everybody. This could be a great inventory for the others in future.

    Best Regards,
    Abhi

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pull cell data from a closed workbook
    By excelrookie92 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2014, 10:12 AM
  2. I need pull the data from closed workbook through assigned path loc
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-21-2014, 07:25 AM
  3. Pull data from closed workbook issue
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-14-2014, 11:59 AM
  4. [SOLVED] VBA pull data from closed workbook depends upon header status !!! need help of experts
    By johnodys in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-12-2013, 07:06 AM
  5. excel userform pull data from closed workbook
    By thameem127 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2013, 01:53 PM
  6. Use VBA to pull data from another closed workbook
    By derryt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-08-2012, 11:09 AM
  7. [SOLVED] Using ADO to pull data from closed workbook.
    By abhay_547 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2010, 06:20 PM

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