dynamic named ranges examples

9
Dynamic Named Ranges Examples For ALL examples you need to: Fill Column A with a mix of text and numeric entries. Go to: Insert>Name>Define and in the Names in workbook box type any one word name (I will use MyRange) the only part that will change is the formula we place in the Refers to box. 1:Expand Down as Many Rows as There are Numeric Entries. In the Refers to box type: =OFFSET($A$1,0,0,COUNT($A: $A),1) 2:Expand Down as Many Rows as There are Numeric and Text Entries. In the Refers to box type: =OFFSET($A$1,0,0,COUNTA($A: $A),1) 3:Expand Down to The Last Numeric Entry In the Refers to box type: =OFFSET($A$1,0,0,MATCH(1E+306,$A:$A,1),1) If you expect a number larger than 1E+306 (a one with 306 zeros) then change this to a larger number. 4:Expand Down to The Last Text Entry In the Refers to box type: =OFFSET($A$1,0,0,MATCH("*",$A: $A,-1),1) 5:Expand Down Based on Another Cell Value Put the number 10 in cell B1 first then: In the Refers to box type: =OFFSET($A$1,0,0,$B$1,1) Now change the number in cell B1 and the range will change accordingly. 6:Expand Down One Row Each Month In the Refers to box type: =OFFSET($A$1,0,0,MONTH(TODAY()),1) 7:Expand Down One Row Each Week In the Refers to box type: =OFFSET($A$1,0,0,WEEKNUM(TODAY()),1) Requires the "Analysis Toolpak" to be installed. Tools>Add- ins-Analysis Toolpak

Upload: shijo-thomas

Post on 19-Nov-2015

6 views

Category:

Documents


0 download

DESCRIPTION

Dynamic Named Ranges Examples

TRANSCRIPT

Dynamic Named Ranges ExamplesFor ALL examples you need to: Fill Column A with a mix of text and numeric entries. Go to: Insert>Name>Define and in the Names in workbook box type any one word name (I will use MyRange) the only part that will change is the formula we place in the Refers to box. 1:Expand Down as Many Rows as There are Numeric Entries. In the Refers to box type: =OFFSET($A$1,0,0,COUNT($A:$A),1) 2:Expand Down as Many Rows as There are Numeric and Text Entries. In the Refers to box type: =OFFSET($A$1,0,0,COUNTA($A:$A),1) 3:Expand Down to The Last Numeric Entry In the Refers to box type: =OFFSET($A$1,0,0,MATCH(1E+306,$A:$A,1),1)If you expect a number larger than 1E+306 (a one with 306 zeros) then change this to a larger number. 4:Expand Down to The Last Text Entry In the Refers to box type: =OFFSET($A$1,0,0,MATCH("*",$A:$A,-1),1) 5:Expand Down Based on Another Cell Value Put the number 10 in cell B1 first then:In the Refers to box type: =OFFSET($A$1,0,0,$B$1,1) Now change the number in cell B1 and the range will change accordingly. 6:Expand Down One Row Each Month In the Refers to box type: =OFFSET($A$1,0,0,MONTH(TODAY()),1) 7:Expand Down One Row Each Week In the Refers to box type: =OFFSET($A$1,0,0,WEEKNUM(TODAY()),1)Requires the "Analysis Toolpak" to be installed. Tools>Add-ins-Analysis Toolpak

The good thing about number 3,4,5,6 and 7 is that they will include blank cells.

You can also change the Columns the dynamic range will span by simply changing the last Argument of the OFFSET function to a higher number than 1.

You could even expand across your Columns dynamically by placing anotherCOUNT or COUNTA formula as the last argument, instead of 1. See below:In the Refers to box type: =OFFSET($A$1,0,0,COUNTA($A:$A),COUNTA($1:$1))

This dynamic range will now also expand across Columns in Row 1. So if you add another Column to your Table the dynamic range will automatically incorporate it.

To try and give you a better understanding of the OFFSET formula, read the text below taken from the Excel help file.

OFFSET(reference,rows, cols,height,width)

Reference : is the reference from which you want to base the offset. Reference must be a reference to a cell or range of adjacent cells; otherwise, OFFSET returns the #VALUE! error value.

Rows : is the number of rows, up or down, that you want the upper-left cell to refer to. Using 5 as the rows argument specifies that the upper-left cell in the reference is five rows below reference. Rows can be positive (which means below the Starting reference) or negative (which means above the Starting reference).

Cols : is the number of columns, to the left or right, that you want the upper-left cell of the result to refer to. Using 5 as the cols argument specifies that the upper-left cell in the reference is five columns to the right of reference. Cols can be positive (which means to the right of the Starting reference) or negative (which means to the left of the Starting reference).If rows and cols offset reference over the edge of the worksheet, OFFSET returns the #REF! error value.

Height : is the height, in number of rows, that you want the returned reference to be. Height must be a positive number.

Width : is the width, in number of columns, that you want the returned reference to be. Width must be a positive number.If height or width is omitted, it is assumed to be the same height or width as reference.

Advanced Excel Dynamic Named Ranges - Expand/Contract Named RangesCurrent Special! Complete Excel Excel Training Course for Excel 97 - Excel 2003, only $145.00. $59.95 Instant Buy/Download, 30 Day Money Back Guarantee & Free Excel Help for LIFE!Advanced Excel Dynamic Named RangesI don't think it's any secret that I'm a pretty big fan of Dynamic Named Ranges They are ideal to be used in a vast array of different situations. I thought I would show you some Dynamic Named Ranges with a twist.BASED OFF LONGEST COLUMN OF DATAA Dynamic Named Range formula for a table of data that occupies say A1:D may look like below;Name: MyTableRefers to: =OFFSET($A$1,0,0,COUNTA($A:$A),4) Where: COUNTA($A:$A) is being used to determine how many rows to expand down and 4 is the number of columns to include Starting from $A$1.This of course will work fine if Column A is the column with the most amount of data and there are no blank cells. But what if you have no idea which of the columns (A:D) will have the most data and if there will be blanks? Let's first address the blank cells issue. On the page, this link points to , you will see that numbers 3 and 4 address the issue of the possibility that there might be blank cells between data. That is;3**Expand Down to The Last Numeric Entry**In the Refers to box type: =OFFSET($A$1,0,0,MATCH(1E+306,$A:$A,1),1)If you expect a number larger than 1E+306 (a one with 306 zeros) then change this to a larger number.4**Expand Down to The Last Text Entry**In the Refers to box type: =OFFSET($A$1,0,0,MATCH("*",$A:$A,-1),1)As you can see though, this does not account for the possibility of text and numbers in the same column. However, we should always have column headings in a table and these are normally text. So to find out the last used cell in Column A we could use;=MAX(MATCH(1E+306,$A:$A,1),MATCH("*",$A:$A,-1))This formula requires that there is BOTH text and numbers in Column A. So, while the Column heading will ensure we have text, we need to ensure there is at least 1 number. To do this, insert a new row at Row 1 (select Row 1 and go to Insert>Rows) and then in A1:D1 enter the number 0. You can now hide this row (select Row 1 and go to Format>Row>Hide). To use this to determine which of the Columns (A:D) has the highest row number we would go to Insert>Name>Define and use these names with the formula below as the result for their "Refers to".ColA=MAX(MATCH(1E+306,$A:$A,1),MATCH("*",$A:$A,-1))ColB=MAX(MATCH(1E+306,$B:$B,1),MATCH("*",$B:$B,-1))ColC=MAX(MATCH(1E+306,$C:$C,1),MATCH("*",$C:$C,-1))ColD=MAX(MATCH(1E+306,$D:$D,1),MATCH("*",$D:$D,-1))Now we can create one more Name (MaxCol) and have this one return the maximum number of the Names above. This would simply be;MaxCol=MAX(ColA,ColB,ColC,ColD)Now we have this done we can replace our original Dynamic Named Range (MyRange) "Refers to" range with=OFFSET($A$1,0,0,MaxCol,4)This will ensure that are named range always expands down to the last used cell in Columns A:D and it doesn't matter if there are blank cells and/or a mix of text and numeric entries.DYNAMIC RANGE WITHIN A RANGEThis Dynamic Named Range is ideal for a long text list that is sorted A:Z. We can also make use of the "List" feature of Validation to make it even better. For the purpose of this example I will assume to list is in Column A and has been sorted A:ZSelect B1 and go to Data>Validation choose "List" then in the "Source" type; A,B,C,D....ZNow go to Insert>Name>Define and use the Name: AlphaList and for the "Refers to" use;=OFFSET(INDIRECT(ADDRESS(MATCH($B$1 & "*",$A:$A,0)+1,1)),0,0,COUNTIF($A:$A,$B$1 & "*"),1)Now, whenever you select a letter from the list in B1 the Dynamic Named Range (AlphaList) will refers to only the group of cells that Start with the letter chosen. In other words, if the list was names (and of course must be sorted A:Z) and you chose the letter "M" from B1, the Dynamic Named Range AlphaList will only refer to the names that Start with "M".The uses of this are only limited to your imagination.Advanced Excel Dynamic Named Ranges - Expand/Contract Named RangesCurrent Special! Complete Excel Excel Training Course for Excel 97 - Excel 2003, only $145.00. $59.95 Instant Buy/Download, 30 Day Money Back Guarantee & Free Excel Help for LIFE!Advanced Excel Dynamic Named RangesI don't think it's any secret that I'm a pretty big fan of Dynamic Named Ranges They are ideal to be used in a vast array of different situations. I thought I would show you some Dynamic Named Ranges with a twist.BASED OFF LONGEST COLUMN OF DATAA Dynamic Named Range formula for a table of data that occupies say A1:D may look like below;Name: MyTableRefers to: =OFFSET($A$1,0,0,COUNTA($A:$A),4) Where: COUNTA($A:$A) is being used to determine how many rows to expand down and 4 is the number of columns to include Starting from $A$1.This of course will work fine if Column A is the column with the most amount of data and there are no blank cells. But what if you have no idea which of the columns (A:D) will have the most data and if there will be blanks? Let's first address the blank cells issue. On the page, this link points to , you will see that numbers 3 and 4 address the issue of the possibility that there might be blank cells between data. That is;3**Expand Down to The Last Numeric Entry**In the Refers to box type: =OFFSET($A$1,0,0,MATCH(1E+306,$A:$A,1),1)If you expect a number larger than 1E+306 (a one with 306 zeros) then change this to a larger number.4**Expand Down to The Last Text Entry**In the Refers to box type: =OFFSET($A$1,0,0,MATCH("*",$A:$A,-1),1)As you can see though, this does not account for the possibility of text and numbers in the same column. However, we should always have column headings in a table and these are normally text. So to find out the last used cell in Column A we could use;=MAX(MATCH(1E+306,$A:$A,1),MATCH("*",$A:$A,-1))This formula requires that there is BOTH text and numbers in Column A. So, while the Column heading will ensure we have text, we need to ensure there is at least 1 number. To do this, insert a new row at Row 1 (select Row 1 and go to Insert>Rows) and then in A1:D1 enter the number 0. You can now hide this row (select Row 1 and go to Format>Row>Hide). To use this to determine which of the Columns (A:D) has the highest row number we would go to Insert>Name>Define and use these names with the formula below as the result for their "Refers to".ColA=MAX(MATCH(1E+306,$A:$A,1),MATCH("*",$A:$A,-1))ColB=MAX(MATCH(1E+306,$B:$B,1),MATCH("*",$B:$B,-1))ColC=MAX(MATCH(1E+306,$C:$C,1),MATCH("*",$C:$C,-1))ColD=MAX(MATCH(1E+306,$D:$D,1),MATCH("*",$D:$D,-1))Now we can create one more Name (MaxCol) and have this one return the maximum number of the Names above. This would simply be;MaxCol=MAX(ColA,ColB,ColC,ColD)Now we have this done we can replace our original Dynamic Named Range (MyRange) "Refers to" range with=OFFSET($A$1,0,0,MaxCol,4)This will ensure that are named range always expands down to the last used cell in Columns A:D and it doesn't matter if there are blank cells and/or a mix of text and numeric entries.DYNAMIC RANGE WITHIN A RANGEThis Dynamic Named Range is ideal for a long text list that is sorted A:Z. We can also make use of the "List" feature of Validation to make it even better. For the purpose of this example I will assume to list is in Column A and has been sorted A:ZSelect B1 and go to Data>Validation choose "List" then in the "Source" type; A,B,C,D....ZNow go to Insert>Name>Define and use the Name: AlphaList and for the "Refers to" use;=OFFSET(INDIRECT(ADDRESS(MATCH($B$1 & "*",$A:$A,0)+1,1)),0,0,COUNTIF($A:$A,$B$1 & "*"),1)Now, whenever you select a letter from the list in B1 the Dynamic Named Range (AlphaList) will refers to only the group of cells that Start with the letter chosen. In other words, if the list was names (and of course must be sorted A:Z) and you chose the letter "M" from B1, the Dynamic Named Range AlphaList will only refer to the names that Start with "M".The uses of this are only limited to your imagination.