+ Reply to Thread
Results 1 to 5 of 5

Passing variable in VLookup string in VBA Code- I get an error

  1. #1
    Forum Contributor
    Join Date
    06-17-2014
    Location
    london
    MS-Off Ver
    365
    Posts
    398

    Passing variable in VLookup string in VBA Code- I get an error

    Hi All

    I would appreciate any help on my problem below

    I want to pass a variable in VLookup function in VBA and keep getting and error.

    I have the following

    Please Login or Register  to view this content.
    What I want for the code above is to replace HW655 WK 5 2016.xlsx] with variable Sheetname so that whatever value Sheetname has it will look at the right file for the vlookup. Sheet name has value of cell t2 in my spreadhseet which will change depending on user input

    But I cant seem to be getting this right as I am not sure how to do this , every time I try it has Sheetname as string in the name and not the value of sheet name
    any help is appreciate it

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Passing variable in VLookup string in VBA Code- I get an error

    Hi,

    This is confusing. HW655...etc is a WORKBOOK name not a sheet name. Please clarify.

    In addition please upload the workbook which has the code and also the HW655...workbook.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    06-17-2014
    Location
    london
    MS-Off Ver
    365
    Posts
    398

    Re: Passing variable in VLookup string in VBA Code- I get an error

    Yes it's is a workbook which changes its name based on cell value. The sheet is called summary which is always come same. In the code I want thecworkbook name which is an external workbook to be replace by Sheet name and there's is always the same I.e thecsheet name and the look-up range . The workbook to too large to send sorry

  4. #4
    Forum Contributor
    Join Date
    06-17-2014
    Location
    london
    MS-Off Ver
    365
    Posts
    398

    Re: Passing variable in VLookup string in VBA Code- I get an error

    sorry for the confusion , to make it clearer the formula I want to use is as follows
    "=VLOOKUP(RC[-1],'[HW655 WK 5 2016.xlsx]SUMMARY SHEET'!C1:C57,5,0)" but I need to replace HW655 WK 5 2016.xlsx by the variable Sheetname (the name of this variable might be confusing but I can change it, it is the name of the workbook). Sheetname is the name of an external workbook which takes its value from a cell in the worksheet based on the user input. I just do nt know how to ut the variable Sheetname in the vlookup formula above instead of HW655 WK 5 2016.xlsx. The sheet in the workbook is called Summary and the lookup range is always the same.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Passing variable in VLookup string in VBA Code- I get an error

    Hi,

    Try
    Please Login or Register  to view this content.

+ 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. [SOLVED] passing a range name as a variable results in error 1004
    By darahsten in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2013, 03:28 AM
  2. [SOLVED] VBA code for passing a variable name as a paramter to Range object
    By vidyuthrajesh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-09-2012, 04:37 PM
  3. Passing String Variable from Command Button Macro to a List Box in same User Form
    By wz4np1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2012, 11:31 AM
  4. Error passing element of string array get ByRef argument type mismatch
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-17-2011, 02:59 PM
  5. Error passing a range to the vlookup function
    By twills in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2011, 02:42 PM
  6. Argument not optional error while passing value of variable between subs
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-30-2010, 05:21 AM
  7. error passing a formula to a cell from a string
    By TheIrishThug in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-22-2005, 11:54 AM
  8. Passing variable from userform to module error
    By mworth01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2005, 12:47 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