Random Post: Mythbusters And Marketing
RSS 2.0
  • Home
  • About
  • MBA Guide
  • Print Ad Blog
  •  

    Excel Dynamic Data Validation Range: Indirect

    magic-trick-799126In the world of dashboard and report generation every little trick can help.  The trick might save you time, make something possible, or just look pretty sweet.  I think that any one of these is a great reason to employ an Excel trick, but I have to be honest; I am partial to the last one.

    The reason that I love Excel tricks that look sweet is that often times if it looks sweet then it is also more likely to be used and appreciated by others.  On top of all of that it can be fun just seeing what Excel can do.  With all of that in mind, I give you my first post on Excel Tips and Tricks: Creating a Dynamic Data Validation Range.

    The first tool that you will need is the “INDIRECT” formula.  The INDIRECT formula takes a text string and evaluates it as a range.  So, whereas normally a formula might say ‘=sheet1!A6’ and INDIRECT would look like ‘=INDIRECT(“sheet1!A6”)’.  The main difference is that the second formula is text and can be broken up into text segments and concanated together like this ‘=INDIRECT(“sheet1″&”!A”&6″)’ which is the key because then any component within the INDIRECT can be part text part cell references, calculations, formulas, etc.  Here’s and example of that ‘=INDIRECT(“sheet1″&”!A”&3*2)’ or if cell B1 had a value of 6 in it ‘=INDIRECT(“sheet1″&”!A”&B1)’.  All of these formulas would return the value that is in sheet1!A6.

    Whew! Take a deep breath after that.  Perhaps take a second to play around with it because the next part relies on it.

    The difficult part about using data validation in a cell is that the data validation range must be in the same sheet as the cell you are validating.  Unless you use a named range.  You cand define a named range in 2 ways.  The first is to select what you want and then in the box in the upper left corner of the sheet type a name.  The second is to use Insert > Name > Define (2003) or Formulas > Defined Names > Define Name >Define Name (2007)

    Here’s the setup.  I am entering “List of Letters” in Sheet2!A1 with letters A – F in column A rows 2 – 7.  Select Sheet2!A1:A7 and type “Data” into that box in the upper left corner.  You should now have a named range called “Data”.

    Then in cell Sheet1!A1 Use Data Validation and select List for the “Allow” drop box.  For the source type “=Data”.  You should now have a drop down in Sheet1!A1 that has all of the values from Sheet2!A1:A7.  Now you have applied Data Validation to a cell that pulls from a list on a separate sheet.  Nice.

    Now for that extra piece of flare.  We need to redefine this named range.  For this go back into the Define Name – select the name and click edit; in 2007 use the “Name Manager”.

    Now, we get to use the INDIRECT from before.  We will start off nice and simple.  While the current name should be defined as ‘=Sheet2!$A$1:$A$7’ we will just make that and INDIRECT so we get : ‘=INDIRECT(“Sheet2!$A$1:$A$7”)’.  Now we want to change this so that we know how far down to go.  Right now we go to A7, but what if things are added.  We would have to redefine the name every time.  Luckily, we can use the COUNTA formula to count the number of non-empty cells.  In this case COUNTA(Sheet2!A:A) should equal 7 (one for the heading and one for each letter).

    Lets throw that into our named range definition in place of the last “7” so that we get: ‘=INDIRECT(“Sheet2!$A$1:$A$”&COUNTA(Sheet2!$A:$A))’.  Notice that we have to put in the quotation and ampersand right before the COUNTA because we are building a text string.  As a final touch lets say that we don’t want the heading the drop-down box in Sheet1!A1.  We have to change the row that the range starts on so we get : ‘=INDIRECT(“Sheet2!$A$2:$A$”&COUNTA(Sheet2!$A:$A))’.

    As a final wrench, lets just say that the list on sheet2 is moved from A1:A7 to A:3:A9 with A1 and A2 blank.  Here we would just have to add something to the formula on the end to pad it for the blank rows and change the starting row.  In this case we would end up with ‘=INDIRECT(“Sheet2!$A$4:$A$”&COUNTA(Sheet2!$A:$A)+2)’

    Let me know your thoughts on this post and if this worked for you!

    This has been a Thought From The Cake Scraps.

    3 responses to “Excel Dynamic Data Validation Range: Indirect”

    1. […] not sure about all of that, though I have done some posts on cool Excel tricks, but I do know one thing.  I don’t have nearly as good of handle on 2007 as I do on […]

    2. […] above average but falling short of the best. This is what I find when I ask people about their Excel skills.  In fact I would wager that this is what most people would say about their skills with any tool […]

    3. […] of coffee or (better yet) go and dig in the data because it is just fun.  But, while focused on automation of reports or dashboards, they fail to understand what is really being asked and only deliver to […]

    Leave a Reply to Thoughts From The Cake Scraps » Blog Archive » You Need Smart Lazy People Cancel reply

    Your email address will not be published. Required fields are marked *