+ Reply to Thread
Results 1 to 5 of 5

Using a variable in an external reference

  1. #1
    Registered User
    Join Date
    01-16-2016
    Location
    Malta
    MS-Off Ver
    Office 2010
    Posts
    3

    Using a variable in an external reference

    Hello everybody, I'm new to the forum but not new to Excel.

    I'd appreciate some help regarding the INDIRECT function. Basically what I am trying to do is the following:

    I have 2 workbooks located in the same directory named 'Club Members' and 'Tickets' which I want to link without making use of any fixed values. The corresponding worksheets are named 'Membership List' and 'Sheet1' respectively. 'Sheet1' gets data from 'Membership List'.

    The working is done in 'Sheet1' and I am using cell K350 purely as an example.
    ='[Club members.xlsm]Membership List'!$K$350

    What I need to do is substitute cell K350 with a variable and after reading other examples in some other inactive threads I understand that this is achieved with the INDIRECT function. I have achieved this so far however it seems I can't figure out the appropriate syntax for the INDIRECT function.

    Inside 'Sheet1' -
    In cell A1 I put the path as a string ----> '[Club members.xlsm]Membership List'!
    In cell A2 I put the variable ----> 200
    In cell A3 I put the INDIRECT function ---> =INDIRECT("'" & $A$1 & "'!A2")

    I'm really not sure about the syntax of cell A3 though.

    I want to use the variable in cell A2 so Excel considers it as ='[Club members.xlsm]Membership List'!$K$200.
    I am getting a ZERO though. The source workbook 'Club Members' was open all the time.

    Any help pointing me in the right direction is much appreciated thanks guys

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Using a variable in an external reference

    Hi, welcome to the forum

    1st thing to note is that INDIRECT does not work on closed workbooks

    2nd, INDIRECT is used to replace text in a formula, so that exxel can use it in that formula. So, in your case, maybe something like...
    A1='[Club members.xlsm]Membership List'!
    A2=200
    A3=INDIRECT("'" & $A$1 &"K"&A2)
    You did not give a column. so I added it to be K
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    01-16-2016
    Location
    Malta
    MS-Off Ver
    Office 2010
    Posts
    3

    Re: Using a variable in an external reference

    Thanks for the warm welcome and for the response

    I have done some extensive research about the INDIRECT function in the past hours but I still could not apply it to my example.

    Yes, both workbooks as explained in my original post are open.
    You were right about me failing to include a column. After applying your revised function now I am getting a #REF!
    but when I try ='[Club members.xlsm]Membership List'!K200 I get the appropriate result though which means that the sheets are actually linked.

    Somehow, either the syntax is still not correct or the variable is not being read properly.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Using a variable in an external reference

    Sorry for the delay

    The INDIRECT is supposed to replace parts of the formula. So what I sometimes do, is create the formula in the normal way, using the mouse/keys - and make sure that is working. then I start to replace (whole) parts with INDIRECT. So if your formula is...
    ='[Club members.xlsm]Membership List'!$K$350

    A1=Club members.xlsm
    so the formula would be...
    =INDIRECT("'["&A1&"]Membership List'!K350")
    if that works OK, we move on and change more...
    A2=Membership List
    =INDIRECT("'["&A1&"]"&A2&"'!K350")
    Then...
    A3=350
    =INDIRECT("'["&A1&"]"&A2&"'!K"&A3)
    Test at each stage and make sure that part works - adjust and fiddle as needed

  5. #5
    Registered User
    Join Date
    01-16-2016
    Location
    Malta
    MS-Off Ver
    Office 2010
    Posts
    3

    Re: Using a variable in an external reference

    You're the man, that worked perfectly. The INDIRECT function at step 3 is finally allowing me to use variables.

    I fiddled one last time with the string and now I got =INDIRECT("'[Club members.xlsm]Membership List'!K"&A3).

    Works to perfection. I will be reading more about this powerful function. Thanks once again.

+ 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] External reference with variable workbook name?
    By KenV in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 02-04-2019, 06:21 PM
  2. External reference with variable workbook name
    By Mister_T in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-23-2014, 06:07 PM
  3. Creating an external reference with a variable
    By ruslruslrusl in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-27-2014, 05:12 PM
  4. External reference with variable sheet name
    By mrossman04 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-26-2012, 04:43 PM
  5. External reference with variable filenames
    By donavank in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-02-2008, 12:32 PM
  6. Variable External Reference:
    By fil in forum Excel General
    Replies: 2
    Last Post: 01-18-2008, 06:33 PM
  7. Create an external reference link with embedded variable
    By Greentree in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-09-2005, 03:05 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