+ Reply to Thread
Results 1 to 4 of 4

VBA Code For Vlookup Function with Table_Array from Another Workbook

  1. #1
    Registered User
    Join Date
    05-30-2014
    Posts
    17

    VBA Code For Vlookup Function with Table_Array from Another Workbook

    Hi,

    I will like to write a VBA code consisting of VLookup function. The problem I face now is that the source of data which i will be pulling the information from is in sheet2 of another workbook and I have tried but failed to come out with a code that work. The code I have so far is as followed. Can someone guide me on how to complete the code to make it work?

    Say the path of the source file is this, C:\Users\Ken\Documents\Book 1.xlsx

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Perth, WA, Australia
    MS-Off Ver
    Office 365
    Posts
    249

    Re: VBA Code For Vlookup Function with Table_Array from Another Workbook

    Use single quotes around everything preceding the exclamation mark separator, thus:

    .Formula = "=VLOOKUP(A2, '[Book 1]Sheet2'!$A$1:$D$" & Sheets("Sheet2").Range("A" & Rows.Count).End(3)(1).Row & ",3,FALSE)"

    The single quotes are only necessary when there is a space or other special characters in the name you are qualifying. The other spreadsheet must also be open at the time and that means you don't have to worry about specifying the full path.
    _______________
    Floyd Emerson
    Business Intelligence Consultant
    Perth, Western Australia

  3. #3
    Registered User
    Join Date
    05-30-2014
    Posts
    17

    Re: VBA Code For Vlookup Function with Table_Array from Another Workbook

    Hi ffffloyd,

    Thanks for the kind explanation and guidance. However, I made some modification to my code and an error message prompt me that the
    "subscript is out of range". The name of my workbook is "May" and the worksheet name is "Expenses" and the workbook are left open. Can
    you help to identified where the problem lies with my code?

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Perth, WA, Australia
    MS-Off Ver
    Office 365
    Posts
    249

    Re: VBA Code For Vlookup Function with Table_Array from Another Workbook

    Hi Darrell,

    Sorry I have not been back for a while; I have only just seen your reply.

    If you haven't already solved this problem, could it be because you are referring to Sheets("Expenses") when Expenses is in that other workbook (May)? You would need to refer to the Sheets array in that workbook, something like: Workbooks("May.xlsm").Sheets("Expenses"). That Rows.Count in the formula looks a little odd too. Does that also need to be the Rows in Workbooks("May.xlsm").Sheets("Expenses")?

+ 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. Vlookup with function in table_array
    By JoshuaEyer in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-03-2025, 05:43 AM
  2. table_array:VLOOKUP help
    By gigiw1986 in forum Excel General
    Replies: 3
    Last Post: 08-28-2010, 02:22 PM
  3. Replies: 1
    Last Post: 12-02-2005, 09:35 AM
  4. VLOOKUP TABLE_ARRAY
    By veljo in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-31-2005, 08:06 PM
  5. Insert Vlookup into table_array of Vlookup with named range
    By Denise in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-24-2005, 07:06 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