+ Reply to Thread
Results 1 to 10 of 10

Formula to reference named ranges

  1. #1
    Registered User
    Join Date
    05-10-2005
    MS-Off Ver
    Office 2007 & 2010
    Posts
    67

    Formula to reference named ranges

    I am trying to create a formula that will "run" a named range that has a complex formula built into it.

    While reading about named ranges to simplify formulas (a simple name instead of a data range, say Sheet1!A1:A100, could be named "Data" or something to shorten and simplify a long formula), I also stumbled upon the idea that instead of a named range referencing a data set, you could actually incorporate a formula into that named range.

    Say I created two named ranges, called FORM1 and FORM2. (in actuality there could be dozens of named range possibilities created)

    In cell A2 is a formula (or my idea) that simply would read very simply =A1. If you type "FORM1" into Cell A1, then A2 would "turn into" the named range formula FORM1, or if you typed "FORM2" into A1, then A2 would "turn into" or run the named range called FORM2.

    Is this possible? All the research I have looked into would call this a dynamic reference (or so I think), however everything I look up returns comments an conversation regarding creating a dynamic reference named range. I don't think I want the named range to be dynamic, just the calling up of the named range.

    I hope this make sense, and I can create a simple example sheet if needed.

    Thanks.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula to reference named ranges

    If I've understood what you mean you'd need to use INDIRECT for that. INDIRECT is a volatile function (it calculates every time any change is made to the workbook rather than just when a change is made that directly affects the cell it's used in) so it can cause performance issues.

    But I could have misunderstood so perhaps that example file would be a good idea.

    BSB

  3. #3
    Registered User
    Join Date
    05-10-2005
    MS-Off Ver
    Office 2007 & 2010
    Posts
    67

    Re: Formula to reference named ranges

    I was thinking along the lines of INDIRECT, and am not opposed to using. I actually use it throughout the remainder of the sheet to dynamically reference data on various tabs. I have experienced slow calculations once I get to a very large worksheet with lots of tabs. Not sure if INDIRECT is the cause of this.

    What would the syntax be using INDIRECT? I have tried =INDIRECT(A1) at its simplest for to replicate the simple example I described, but I get a #REF error.

    I will work on an example file.

    EDIT:
    The attached shows what I am trying to achieve. I went ahead and used INDIRECT (or at least how I thought it could be used) in cell G3. You can see the #REF error. My thought is you would choose what type of formula using the drop down menu in F, and the result of that choice would be in G (where I would like the formula to reference the named range). I included columns I-K just for value checking in this case.

    Note that the 3 formulas that have been created are very simple, when the actual final formulas in the named ranges will be more complex. Also I only included 3 for the example, ideally this would work with a much larger amount, easily 10+, so I don't think a nested IF statement would be a good choice. Also, I would be forced to type the names of the named ranges into the nested IF. Since the names of the named ranges could be changed or added/subtracted as needed, this is another reason I would like to avoid a nested IF.

    Hope the attached is helpful.
    Attached Files Attached Files
    Last edited by lil_ern63; 03-22-2019 at 03:29 PM.

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula to reference named ranges

    If you have lots of INDIRECT formulas, or any of the volatile functions, then it's highly possible that is the cause of the sluggishness. Certainly a contributing factor anyway.

    I think we need to see a sample workbook that explains exactly what you're trying to do.

    BSB

  5. #5
    Registered User
    Join Date
    05-10-2005
    MS-Off Ver
    Office 2007 & 2010
    Posts
    67

    Re: Formula to reference named ranges

    I just posted a sample file, it was attached to my previous post.

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula to reference named ranges

    What should the result be where it says REF?

    BSB

  7. #7
    Registered User
    Join Date
    05-10-2005
    MS-Off Ver
    Office 2007 & 2010
    Posts
    67

    Re: Formula to reference named ranges

    For the file as it was posted, it would be 1.93, since the dropdown box said to use the AREA formula. Whatever the solution (formula) is, would be copied and pasted into column G, and then dragged down from row 3 to 8. As you change the formula in the dropdown in Column F, the value in column G would change.

    I just posted the file with an INDIRECT function. I had once thought INDIRECT was the way to go, but I can't get anything to come up other than REF. So either my syntax within the INDIRECT is wrong, or INDIRECT can't be used.

  8. #8
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula to reference named ranges

    OK, I understand what you're trying to do now and I'm not sure INDIRECT is the right approach after all.

    This is not something I've ever needed to do so I don't know if it can be done the way you're thinking, however, there are possible solutions.

    One would be to use helper columns like you have in columns I to K at the moment. I know they are only there for checking purposes but if you had all your formulas laid out like that then hidden away you could use a lookup formula like the below to return the relevant result.
    In G3 and copied down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Of course if there are lots of formulas and lots of rows of data this could cause sluggish response from the workbook so may not be ideal.

    My preferred option would be VBA. If that's an option for you then a simple worksheet change event would pick up whenever the values in column F are changed and put the appropriate formula in column G.

    Something like this in the worksheet module:
    Please Login or Register  to view this content.
    Other than that I'm stuck for ideas.

    BSB

  9. #9
    Registered User
    Join Date
    05-10-2005
    MS-Off Ver
    Office 2007 & 2010
    Posts
    67

    Re: Formula to reference named ranges

    BSB,

    Currently I was thinking, and have set up the helper column idea, but as you mentioned, this could be come cumbersome as the number of options grow, along with lines grows (currently only F3:F8 in the sample), and number of tabs grow. As mentioned, this could create a very sluggish file if any of these items becomes too large, especially as tab counts grow. This is something I have just had to deal with as it has happened, but would like to minimize its effects if at all possible.

    Now, onto the VBA solution,

    I'm not terribly familiar with VBA, or how to implement/call up. I saved the sheet as a Macro enabled workbook, and inserted a new module. I copied and pasted your code, but then after that I am lost. I tried changing the dropdown in column F, but nothing changed. I tried to write a formula called Worksheet_Change (thinking it was a user defined function), but wasn't working, just needing a little help.

    Now, once I get the VBA working a few questions:
    Would this still work if the names in the drop down change, or the list becomes longer? (i.e. new formulas are added, or the current ones are updated and renamed).
    Also, looking at the code, it appears to be set to check the range F3:F8, as this was the portion on the sample sheet. Is there a way to have this possibly expandable? Say from F3:F8, but if a row is added between 3 and 8, would this automatically increase from 3 to 9?

    And if VBA is the only way to go, I understand. While I don't have an understanding of VBA, I am under the impression, VBA really opens the possibilites to limited by only imagination and ingenuity. That being said, I am building this for use in my company, and the company isn't a fan of VBA/Macro enable workbooks and therefore won't allow emailing of spreadsheets with those properties. While I am confident BSB's solution will work (with maybe some minimal adjustments and learning on my part), I would still be interested in a non VBA solution if there is one. So I will gladly run with BSB's solution, but either to him/her, or anyone else, I just wanted to keep the question open for other solutions (if there are any).
    Last edited by lil_ern63; 03-25-2019 at 12:51 PM.

  10. #10
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula to reference named ranges

    The code I provided previously was merely a demonstration of one method that may have worked for you.

    I've slightly advanced that approach in the attached by using a table and a dynamic named range.

    The table ensures you don't need to drag your data validation in column F down further than your data goes (the table will expand downward when you add new rows of data).

    The dynamic named range (called BSB ) counts the number of rows in the table and by adjusting the defined range (F3:F8) in the VBA previously it all works out well in the end.

    Now, if your company doesn't allow VBA (many do not) then this is all a moot point. But if they do then you've got yourself a nifty (free) solution to a small problem.

    If the company is of any decent size then an IT network is more than likely in place and emailing this file about shouldn't be an issue as it could be put in a central folder and accessed from there.

    If you want a formula only solution then you'll be waiting for someone else to pick the query up or you'll be paying hundreds of dollars an hour for me to spend time on a non VBA solution.

    I'm happy for you to go either way on that

    BSB
    Attached Files Attached Files

+ 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] circular reference resulting from named ranges and offsets
    By mynameisnfs in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-18-2018, 10:10 AM
  2. Working with named ranges in VBA. Proper way to reference from VBA?
    By OldManExcellor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2014, 05:28 PM
  3. Replies: 1
    Last Post: 05-22-2013, 01:49 AM
  4. [SOLVED] Using text entries to reference named ranges
    By dow400 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-20-2013, 09:07 AM
  5. Reference Named Ranges in a formula based on a cell
    By AiriA in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 11-29-2012, 05:28 PM
  6. Replies: 1
    Last Post: 03-21-2006, 06:40 PM
  7. Named ranges vs cell reference
    By pobuckley in forum Excel General
    Replies: 1
    Last Post: 02-03-2005, 01:42 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