How to create a dynamic range source(转)

Refer to http://www.contextures.com/xlDataVal05.html

Refer to http://www.mrexcel.com/forum/excel-questions/188444-auto-increment-source-range-drop-down-list-box.html

One way is to define a 'Dynamic' named range via insert/name/define and use a formula like this instead of a cell reference. The range will then accomodate additions. Mustn't include blank cells or have anything else in the column though. This starts at cell A1 using column A.
= OFFSET(Mysheet!$A$1,0,0,COUNTA(Mysheet!$A:$A),1)

1. Create and save a workbook (MyLists.xls, in this example)

2. Enter a list of names in cells A1:A2 on Sheet 1.

3. To create a dynamic range, choose Insert|Name|Define(or Formulas|Name Manager|)

4. Use Employees as the range name, and the following formula: =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),1)

5. In another sheet, in one cell, choose Data|Data Validation|Allow List, and source: =Employees   (Note: Please donot forget =), and click OK

PS:

=OFFSET function:

Returns a reference to a range that is a specified number of rows and columns from a cell or range of cells. The reference that is returned can be a single cell or a range of cells. You can specify the number of rows and the number of columns to be returned.

Syntax

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

The OFFSET function syntax has the following arguments (argument: A value that provides information to an action, an event, a method, a property, a function, or a procedure.):

  • Reference Required. The reference from which you want to base the offset. Reference must refer to a cell or range of adjacent cells; otherwise, OFFSET returns the #VALUE! error value.
  • Rows Required. 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 Required. 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).
  • Height Optional. The height, in number of rows, that you want the returned reference to be. Height must be a positive number.
  • Width Optional. The width, in number of columns, that you want the returned reference to be. Width must be a positive number.

=COUNTA function:

The Excel Counta function returns a count of non-blanks within a supplied set of cells or values.

The function is commonly used to return the number of non-blank cells in a range. However, as well as ranges of cells, the Counta function can directly received arrays of values, which are not stored in cells.

COUNTA( value1, [value2], ... )

Where the arguments, value1, [value2], etc, can be any values or references to cell ranges.

posted on 2013-01-14 23:13  -Anny-  阅读(225)  评论(0编辑  收藏  举报