+ Reply to Thread
Results 1 to 10 of 10

Creating an external reference with a variable

  1. #1
    Registered User
    Join Date
    02-27-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Creating an external reference with a variable

    Hi all,

    I'm wondering if there's any way to put a variable for a cell address in an external reference formula. Basically, I'm creating an abridged report of customer data that takes a single customer's info from 2 other workbooks on a networked drive and compiles the chosen cell data into one worksheet summary of their info. The base external reference formula looks like this:

    ='F:\Projects\[CustomerDB.xls]Sheet1'!VariableCellGoesHere

    I want to know if there's a way I can make the formula use a variable cell address that I can just type into another cell to tell it which row I need to grab info from. Generally, all of the customer data I need is spanned across multiple columns in one single row. The formula above appears multiple times in the sheet I'm trying to make. The first is for "Name", the next is for "Address", next is "Phone Number", etc. So for instance, if I want customer data from the main spreadsheet and that customer's info is on row 355, my first few formulas are:

    ='F:\Projects\[ProjectDB.xls]Sheet1'!$A$355
    ='F:\Projects\[ProjectDB.xls]Sheet1'!$B$355
    ='F:\Projects\[ProjectDB.xls]Sheet1'!$C$355

    Is there a way I can maybe have a designated cell where I just enter the row number I need (e.g. 481) so the formula sees that number and plugs it into the cell reference above resulting in the formulas adjusting themselves to ='F:\Projects\[ProjectDB.xls]Sheet1'!$A$481? Or is there another way to do this?

    Any help/suggestion is greatly appreciated. Thanks.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2508 Win 11
    Posts
    24,958

    Re: Creating an external reference with a variable

    I think that you can do this using the indirect function.

    Look at this link

    http://www.techonthenet.com/excel/formulas/indirect.php

    In Cell A1 you would have your path as a string
    In Cell A2 you would type 481
    In cell A3 you would have this formula =Indirect(A1) & A2 to get your total formula
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    02-27-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Creating an external reference with a variable

    Quote Originally Posted by alansidman View Post
    I think that you can do this using the indirect function.

    Look at this link

    http://www.techonthenet.com/excel/formulas/indirect.php

    In Cell A1 you would have your path as a string
    In Cell A2 you would type 481
    In cell A3 you would have this formula =Indirect(A1) & A2 to get your total formula

    Hmmm, I'm trying this but it's not working. Maybe I'm not getting the syntax correct. I have:
    A1 > F:\Projects\[CustomerDB.xls]Sheet1
    A2 > 384 (decided to test this number instead of 481 since it's the one I'm working on)
    A3 > =Indirect(A1) & A2

    But I'm getting a #REF! error. Any suggestions?

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2508 Win 11
    Posts
    24,958

    Re: Creating an external reference with a variable

    You need to make sure that the apostrophe's and exclamantion point that you have in the actual formula are part of the string.

    If necessary you may need to concatenate them to your string.

    ie. in A1 " ' " & F:\Projects\[CustomerDB.xls]Sheet1 & " ' !"

    You may have to play with this a bit to get it to work.


    EDIT: My bad. You actually need to do this in cell A3

    =INDIRECT("'"&A1&"'!"&A2)
    Last edited by alansidman; 02-27-2014 at 01:34 PM.

  5. #5
    Registered User
    Join Date
    02-27-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Creating an external reference with a variable

    Quote Originally Posted by alansidman View Post
    You need to make sure that the apostrophe's and exclamantion point that you have in the actual formula are part of the string.

    If necessary you may need to concatenate them to your string.

    ie. in A1 " ' " & F:\Projects\[CustomerDB.xls]Sheet1 & " ' !"

    You may have to play with this a bit to get it to work.


    EDIT: My bad. You actually need to do this in cell A3

    =INDIRECT("'"&A1&"'!"&A2)
    Hmm, I entered exactly what you wrote above for A1 and A3. Excel is adding an extra single quote in the front of the string in A1 and I can't get it to stop doing that. I'm still getting the #REF! error. I've never used this formula before so I'm pretty confused by all the quotes and ampersands... Sorry to be so clueless. Your help is appreciated.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2508 Win 11
    Posts
    24,958

    Re: Creating an external reference with a variable

    In a different workbook, I put the following in the indicated cells

    G22 '[Personal.xls]Main Sheet
    G23 A1
    G24 =INDIRECT("'"&G22&"'!" & G23) ------->Note the single quotes inside the double quotes.

    The result I get is the value in Cell A1 of my workbook Personal.xls on the Tab called Main Sheet.

    So, it works. Double check your input and formula.

    Alan

    EDIT: From the Excel help file:
    "If the source workbook is not open, INDIRECT returns the #REF! error value".
    Last edited by alansidman; 02-27-2014 at 04:25 PM.

  7. #7
    Registered User
    Join Date
    02-27-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Creating an external reference with a variable

    Quote Originally Posted by alansidman View Post
    In a different workbook, I put the following in the indicated cells

    G22 '[Personal.xls]Main Sheet
    G23 A1
    G24 =INDIRECT("'"&G22&"'!" & G23) ------->Note the single quotes inside the double quotes.

    The result I get is the value in Cell A1 of my workbook Personal.xls on the Tab called Main Sheet.

    So, it works. Double check your input and formula.

    Alan

    EDIT: From the Excel help file:
    "If the source workbook is not open, INDIRECT returns the #REF! error value".
    Is the fact that it's pulling from my network drive a possible issue? When I copied the master sheet to my local hard drive and used your code above, it worked. But trying it using the path as F:\Projects\[CustomerDB.xls]Sheet1 I'm getting the error. I have CustomerDB.xls open...

    EDIT: Well, I guess it was just being weird. I closed both workbooks and reopened them and they started working. smh... Thanks for your help. Super appreciated!!
    Last edited by ruslruslrusl; 02-27-2014 at 04:50 PM.

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2508 Win 11
    Posts
    24,958

    Re: Creating an external reference with a variable

    I truly don't know. Did you see my Edit about the file not being open?

    BTW: Forum Courtesy is to only copy and quote that part of the preceding response that is relevant to your remarks. Otherwise it takes up real estate and does not add to the conversation.

  9. #9
    Registered User
    Join Date
    02-27-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Creating an external reference with a variable

    Quote Originally Posted by alansidman View Post
    I truly don't know. Did you see my Edit about the file not being open?

    BTW: Forum Courtesy is to only copy and quote that part of the preceding response that is relevant to your remarks. Otherwise it takes up real estate and does not add to the conversation.
    The problem was that I had 2 separate instances of Excel open so I could have one open on each of my screens. Apparently the reference won't work in this situation. I had to close both spreadsheets and reopen them both within the same instance of Excel for them to work.

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2508 Win 11
    Posts
    24,958

    Re: Creating an external reference with a variable

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. 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. 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. Variable file name for creating external links
    By cbmurphy in forum Excel General
    Replies: 3
    Last Post: 04-15-2013, 02:12 PM
  3. External reference with variable sheet name
    By mrossman04 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-26-2012, 04:43 PM
  4. External reference with variable filenames
    By donavank in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-02-2008, 12:32 PM
  5. Variable External Reference:
    By fil in forum Excel General
    Replies: 2
    Last Post: 01-18-2008, 06:33 PM

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