+ Reply to Thread
Results 1 to 3 of 3

Variable File Reference and Variable Table Array in VBA VLOOKUP

  1. #1
    Registered User
    Join Date
    11-28-2011
    Location
    Singapore, Singapore
    MS-Off Ver
    Excel 2007
    Posts
    19

    Variable File Reference and Variable Table Array in VBA VLOOKUP

    Example: I have a folder "C:\2011\" containing 3 files:
    "Record_03 Nov.xlsx"
    "Record_12 Apr.xlsx"
    "Record_25 May.xlsx"
    In these files above, there is only one sheet named "Summary"

    In my current active sheet, i need a vlookup function in cell Q2. Table Array (Column P:Q) is from the file with latest date (in file name) in folder "C:\2011\". And the number of rows in this table array is variable for each file.

    I manage to write a code to find the file name with latest date. But I couldn't set the vlookup to reference that file.

    Error message: "Application-defined or Object-defined Error"

    Any ideas???

    Please Login or Register  to view this content.
    Last edited by Gingeiko; 11-29-2011 at 08:00 PM.

  2. #2
    Registered User
    Join Date
    11-28-2011
    Location
    Singapore, Singapore
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Variable File Reference and Variable Table Array in VBA VLOOKUP

    Base on my first post, with the files available in C:\2011, I need to have the following formula in cell Q2:

    =VLOOKUP($P2,'C:\2011\[Record_03 Nov.xlsx]Summary'!P:Q,2,FALSE"

    I realize by using P:Q in the table_array, it already tackles the problem of table with variable rows.

    So the only problem left is..I need the "03 Nov" as a variable. Reason: I want to open the file with latest date in C:\2011.

    I would appreciate your ideas. Thank you!

  3. #3
    Registered User
    Join Date
    11-28-2011
    Location
    Singapore, Singapore
    MS-Off Ver
    Excel 2007
    Posts
    19

    [SOLVED] Variable File Reference and Variable Table Array in VBA VLOOKUP

    Ok, PROBLEM SOLVED! Key is to set whole file name as variable, without the path in that same variable. Anyway code is as below:

    In this code, it will open the old file that is being referenced too. And the workbook in which the vlookup formula should be is "Your_Current_New_Workbook.xlsx"

    Please Login or Register  to view this content.
    Last edited by Gingeiko; 11-29-2011 at 07:59 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