+ Reply to Thread
Results 1 to 3 of 3

VLOOKUP - with File Name as a Variable (not working)

  1. #1
    Registered User
    Join Date
    08-28-2019
    Location
    New York
    MS-Off Ver
    2019
    Posts
    2

    VLOOKUP - with File Name as a Variable (not working)

    Hello Experts,

    I have a VLOOKUP Command that works - when executed in Isolation such as

    =VLOOKUP("BALANCE",'\\Network-One\Collections\Summary\[SUMMARY_20190826.xlsx]Report'!$A$4:$H$40,8,FALSE) - This piece of Code works

    I make the date as a Variable (say within a Sub Routine / Function) - by doing the following:

    Date1 = Format(Now() - 1, "YYYYMMDD")
    sPath = "\\Network-One\Collections\Summary\"
    sFile = "SUMMARY_" & Date1 & ".xlsx"
    sheetname1 = "Report"
    Misc1 = "VLOOKUP("

    Concatenate all of the above (to arrive at a VLOOKUP Statement - similar to the one that ran successfully (as posted in line 3 of this request above)

    Misc2 = Misc1 & lookup1 & "," & "'" & sPath & "[" & sFile & "]" & sheetname1 & "'!" & Range1 & ",8, False)"

    MsgBox ExecuteExcel4Macro(Misc2)

    I KNOW - I am doing something wrong - is it perhaps using VLOOKUP incorrectly (or perhaps "ExecuteExcel4Macro" ?)

    Your assistance is greatly appreciated.

    Thank you
    Last edited by vgopalk; 08-29-2019 at 02:46 PM.

  2. #2
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: VLOOKUP - with File Name as a Variable (not working)

    Your Misc2 works out as;

    Please Login or Register  to view this content.
    You've not defined Lookup1 or Range1 in your parameters in the post but I'm guessing this is an oversight in your Post?

    Perhaps if you posted your actual code then we'd get a better idea of what might be going wrong?

  3. #3
    Registered User
    Join Date
    08-28-2019
    Location
    New York
    MS-Off Ver
    2019
    Posts
    2

    Re: VLOOKUP - with File Name as a Variable (not working)

    Hello PaulSp8,

    You are right - in my urgency - I missed out a few parameters (and to provide Values to them)

    Here is the function:

    **

    Function GetVal1() As Variant

    Dim Date1, sPath, SFile, sheetname1, Misc1, Misc2, lookup1, range1 As String

    Date1 = Format(Now() - 1, "YYYYMMDD")
    sPath = "\\Network-One\Collections\Summary\"
    SFile = "SUMMARY_" & Date1 & ".xlsx"
    sheetname1 = "Report"
    Misc1 = "VLOOKUP("
    lookup1 = """BALANCE"""
    range1 = "$A$4:$H$40"

    'Concatenate all of the above (to arrive at a VLOOKUP Statement - similar to the one that ran successfully (as posted in my Original request)

    Misc2 = Misc1 & lookup1 & "," & "'" & sPath & "[" & SFile & "]" & sheetname1 & "'!" & range1 & ",8, False)"
    MsgBox Misc2

    MsgBox ExecuteExcel4Macro(Misc2)

    End Function

    **

    Thanks

+ 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. I try to put if formula with vllokup but its not working
    By sourabh24u in forum Excel General
    Replies: 13
    Last Post: 05-27-2018, 06:58 PM
  2. Filter with a variable and select sheet with a variable not working
    By Jubb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-29-2017, 04:23 PM
  3. [SOLVED] Vlookup formula with variable file name and sheet name not working....help!
    By orozvik in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2015, 10:36 AM
  4. Replies: 0
    Last Post: 01-27-2013, 12:13 PM
  5. Vllokup
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-01-2006, 05:40 AM
  6. Using VLLOKUP
    By Cessna12 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-24-2005, 07:06 PM
  7. [SOLVED] Using VLLOKUP
    By Cessna12 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-24-2005, 09:12 AM

Tags for this Thread

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