Вы находитесь на странице: 1из 7

Using drop down lists in your Excel spreadsheet to select data

If you wish to present a user with a restricted choice of options and don't want to risk an item being miss-typed in a cell, drop down lists are an ideal solution. These lists display all of the available choices to the user so that they can click on their preference. Excel allows you to place two different types of drop down list on your worksheet - either a validation list or a form object.

A validation drop down list

These lists are contained within a cell on your worksheet and the drop down arrow (to the right of the cell) does not appear unless the cell is selected. To add a list to a worksheet place the cursor in the required cell and then selectData | Validation | Settings. In the dialog box select 'Allow: List' and ensure the 'In-cell dropdown' box is ticked. The source data refers to a range of cells containing the selection of options. If you use the mouse to point to a range of cells (e.g. H12:H15), they must normally be contained on the same worksheet. If however you have named the range of cells (e.g. '=ConsNames') containing your data, it can be anywhere in the workbook. In the example (right) the list has been placed in cell B2. Having selected 'Mrs Plain' the formulae in the table (B3:D8) lookup values in a range of data and summarise it. The consultant name can be referred to by the cell name (B2). If you wish to know the position of the selected item within the original range of options (i.e. the four names), an additional formula is needed. In cell B9, the formula =MATCH(B2, H12:H15, 0) determines that Mrs Plain is the second item in the list.

Using a combo box or a list box

These are independent objects (or controls) that can be placed onto a worksheet and are not contained within a cell as such. The example (left) contains a combo box but your choice of object can depend on the amount of space on your worksheet and the number of options.

To obtain these controls you must open the Forms toolbar (View | Toobars | Forms). Then click on either of the list buttons and drag an outline for the object on your worksheet. To instruct the new control where to find it's source data, right click on it, then choose Format Controlfrom the short menu. On the 'Control' tab of the dialog box, enter the range of cells containing the list options. The 'Cell Link' refers to a cell where you wish the list box to place a numeric value representing selected item. In the example above cell B21 is linked and indicates that the third list item was selected. You cannot refer directly to the value in the list box, but the option number in your worksheet cell is automatically updated to reflect any change in the control object. To determine the actual name of the selected item (i.e. Dr Tiswas), use a formula such as =OFFSET(H11, B21, 0) where H11 is the cell immediately above the options list and B21 contains the option value. (Click here for details about the OFFSET function).

Excel Functions: Vlookup, Isna, Match


The VLOOKUP function is commonly used to get details from a table of data. A specified value is looked for in the first column and a value from an adjacent column is returned. =VLOOKUP(SearchItem, TableRange, ColumnNo, Exact). For example you may search for a surname in a list and then return a phone number from another cell on the same row.
A study by accountants Coopers and Lybrand has shown that 90% of spreadsheets with more than 150 rows contain errors. Check out my information on creating well designed spreadsheets.

The SearchItem represents the item being sought and can either be an absolute value (eg 234 or "Fish") or a cell reference. The TableRange represents the range of the whole table (excluding headings) where the left most column contains the values being searched. The ColumnNo specifies which adjacent column contains the value to be returned if the search is successful (where the left most column is 1). The Exactargument is important. If ignored or set to 1, the function will assume that the data is sorted in ascending order and the next value will be returned if the SearchItem can not be found. In the example below a search for XN44 would fail but will return a value adjacent to the next highest item i.e. XN46. If set to zero an exact match must be achieved or else an error (#N/A) will result. A value of zero therefore means that the data does not need to be sorted in ascending order. In some situations the match must be exact and an error will spoil the functioning of the worksheet. Avoiding this problem requires a combination of different functions in a complex formula. It is possible to test whether an exact match can be found using the MATCH function. =MATCH(SearchItem, ColumnRange, Exact) If no match is found, an error will again appear but this can be tested for using the ISNA() function. ISNA() will return a True value if the formula it is looking at results in an #N/A error. These functions could be combined with IF() to return either an exact match or zero.
3 4 Grade 5 XN41 6 XN46
Salary 10000 15000 Staff 3.0 5.0

2 Nursing Staff

www.MeadInKent.co.uk

For a detailed site indexclick here

7 XN51 8 9 10 Select grade 11 Check selection 12 Total salary cost


Employers on Costs (approx)

20000

2.0 12%

XN46 XN46 Found 84000.00

In the example a user can enter a Grade Code in cell D10. In cell D11 the value is checked to see whether an exact match is found and an appropriate message returned. In cell D12 the salary for the selected grade is multiplied by the number of staff and the employers 'on costs'. In this case it is essential to know that the calculation is not based on an approximate match with another grade.
in cell D11 =IF(ISNA(MATCH(D10, B5:B7, 0)), D10 & " is NOT on the Table", D10 & " Found") in cell D12 =VLOOKUP(D10, B5:D7, 2, 0) * VLOOKUP(D10, B5:D7, 3, 0) * (1+D8)

IF(), ISNA() and VLOOKUP() or MATCH() can all be combined into a single safe formula for a lookup. The following formula will return a salary for a grade or zero if the grade code is not found: =IF(ISNA(MATCH("XN51", B5:B7, 0)), 0, VLOOKUP("XN51", B5:D7, 2, 0)). Note that the MATCH() element of the equation could be replaced with a repetition of the VLOOKUP function which will produce the same #N/A error if the exact value isn't found. VLOOKUP() can be used to return a value relating to a single record. If you wish to SUM() or COUNT() one or more records which meet a particular condition (or search item) you can use other functions such as arrays or SUMPRODUCT().

SumProduct function: an alternative to arrays for conditional calculations


SUMPRODUCT() is an extremely versatile function which can be used in different ways. Excel Help gives only a limited idea as to the many uses of this tool. The final section below illustrates how SUMPRODUCT() can easily replace many Array functions which some users are wary of using due to the peculiar key combinations.

1. The basic function


Its primary purpose is to multiply corresponding components in the user defined arrays, and return the sum of those products. It takes the format =SUMPRODUCT((array1)*(array2)* ...). It can contain up to 30 different arrays. The following example shows a simple model to calculate the cost of four different clinical procedures. Six main elements (or cost drivers) have been identified: days spent on a ward; the time spent in operating theatre; the hours of physiotherapy; the number of outpatient attendances required; the cost of drugs and the cost of dressings. If the number of patient episodes (in column C) are multiplied by the quantity of a cost driver (e.g. hours of physiotherapy) you can calculate the total quantity of physiotherapy resources that will be required i.e. (80x6) + (45x1) + (150x2). This lengthy formula (in cellF10) can be replaced by =SUMPRODUCT(($C$6:$C$9)*(F6:F9)) .

4 Procedure Costing model 5 Proc Type 6 A 7 B 8 C 9 D 10


Emergency Elective Elective Emergency Total Resources

meadinkent.co.uk

Episodes Ward Days Theatre Hrs Physio OutPat Drugs Dressings 80 45 50 150 325 4.00 3.00 3.50 5.00 1380 1.50 6.00 0.50 1.00 0.50 0.00 0.75 2.00 280 825 3.00 3.00 480 280 250 200 100 350 86500

1.00 1350 3.00 400

875 178500

[a] A table of activity data for a costing model

2. Using more complex arrays


For the data in the table above to become a useful costing model it needs two further developments:

the number of episodes must be multiplied by all of the various cost drivers (i.e. the whole range D6:I9). the items such as Ward Days must be multiplied by their standard cost in order to convert everything into financial values.

The following table contains the costs of each element (e.g. each day a patient occupies a bed on a ward costs 87). Note that drugs and dressings are already specific cost values and therefore have no common costs.
2 D
87.00

E
685.00

F
19.00

1 Cost / Day Cost / Hour Cost / Hour Cost / Attend Value Value
23.00 1.00 1.00

[b] Standard costs for each cost driver

SUMPRODUCT() will accept the whole range of cost drivers as a single array (D6:I9) and will also allow you to enter another array of costs (D2:I2) which is the same width but of a different depth (only 1 row).
12 13 14 15 C
Report Total cost Episodes Avg cost

D
Total 612660 325 1885

E
Emergency 453942 230 1974

F
Elective 158717 95 1671

[c] Outputs of the costing model using the SumProduct function

The formula in D13 multiplies the numbers of episodes by the quantity of resources and by the cost of each element. =SUMPRODUCT((C6:C9)*(D6:I9)*(D2:I2)). The final row (15) shows the average cost of each type of procedure and is simply calculated by dividing the total cost by the number of episodes.

3. Performing SUMs only where particular conditions are met


An Excel array function can be used to add up or count a selected range of values which meet a specified 'IF' criteria. It only allows a single condition to be specified.

SUMPRODUCT() can perform calculations using any number of different criteria (within the limit of 30 different arrays). In the example above, cell E14 calculates the number of episodes meeting a condition that the Type of procedure (in cells B6:B9) must be an 'Emergency'. The formula is =SUMPRODUCT((C6:C9)*($B$6:$B$9="Emergency")). The value above it in cell E13 is similar to D13, only with an extra array condition added. Instead of each array argument being a range of cells to be multiplied, one of the arrays has now become a condition (or criteria) specifying the items to be SUMmed. You can use adapt this formula to include numerous different rules e.g. =SUMPRODUCT((C6:C9) * (F6:F9) * ($B$6:$B$9<>"Elective") * (F6:F9<5)). In this illustration episodes are multiplied by hours of physiotherapy only where the type is not elective and the number of hours of physiotherapy is less than 5. The answer is 300.

4. Other forms and uses of the SumProduct function


All of the examples above contain the '*' operator to symbolise mulipication of each pair of values. The function can return other mathematical values by using /+ or - instead. It can be adapted to perform a COUNT function by using a formula such as =SUMPRODUCT(($H$6:$H$9>450)*1). This counts the number of procedures where the Drugs cost per patient exceeds 450. The function is ideally suited to calculating weighted averages - something which Excel does not provide a specific function for.

Excel Functions: Using an Array formula


An array is simply a series of data, which in a spreadsheet is normally stored in a range of adjacent cells. Excel however can do special things with arrays that may be used as a flexible alternative to the database functions such as DSUM.

Many functions such as SUM or MAX can be combined with the IF function using arrays. This means that the sum or average function will be performed on only those items that meet a criteria. In other words, the values supplied as an argument to the sum function

are conditional upon a value in an another column or location. The following example should give you an insight as to the potential uses of array functions. A table of values (E5:G12) can be interrogated using the criteria values entered into cells F14 and H14 in order to extract summary information. The first query (in cell G16) returns the total number of items processed by operator 'AK' throughout the whole table. The second (G17) gives the highest number of items processed on a day in April (month 4).

{=SUM(IF(G6:G12=$H$14, F6:F12, 0))}

Sum values in F6:F12 where corresponding values in G6:G12 are equal to H14

{=MAX(IF(MONTH(E6:E12)=F14, F6:F12, The maximum value in F6:F12 where the corresponding month 0))} in E6:E12 equals F14

Both of these are Array formulae - this is evidenced by the curly brackets {braces}. When you enter an array formula there are three rules you must follow:

Instead of typing <Enter> to place the function in a cell, you must type <Ctrl> + <Shift> + <Enter>. If you don't do so, the formulae probably won't make sense and will cause an error. You can not type the Braces {}. They are entered automatically with the above key combination. The array ranges (for the criteria and the values) must be the same size (ie the same number of rows) although they need not be in adjacent columns.

These array functions can be used in a range of situations where the criterion ranges required by database functions (eg DSUM) would be unwieldy. In other situations the SUMIF or COUNTIF functions may be better still. A peculiar use of an array function is to add up a range of numbers which have been entered as text. If a range of numeric values have been converted and formatted using the TEXT function they can no longer be added using the SUM function. The following formula however should do the trick {= SUM(VALUE(range_of_cells)) }. Remember to use <Ctrl> + <Shift> + <Enter>. In normal use the VALUE function converts a single text number into a numeric value. The array functions are limited to applying a single criteria range against each calculation. This can be limiting if you want to add up all of the items processed by operator AK during April. Another function called SUMPRODUCT can overcome this limitation.

OFFSET() is a versatile function with many uses. It enables you to create flexible worksheets in which users can view various results based on different ranges of data depending on an input variable - for example by choosing a different month number. OFFSET() returns a value from a cell which is at a specified number of rows and columns away from a particular cell reference. It is in the format: =OFFSET(BaseRef, Rows, Cols,RowRange, ColRange) . BaseRef is a cell address from which the number of Rows and Columns are counted (a relative reference) and can be located anywhere on your worksheet (although the top left hand corner of a table is conventional). RowRange andColRange are optional and can specify a height and width of

a range of cells (e.g. 4 rows high by 1 column wide would represent all of the values for one of the months in the table below). CHOOSE() allows you to retrieve a particular value from a list of options.=CHOOSE(Value, Option1, Option2 ....) The value is a number which specifies the position of an item from a list of options (e.g. a value of 3 returns the 3rd option which may be either text, another number, or a cell reference). An individual option can be a cell reference but you cannot specify a range of cells to represent the list of options within the function itself.
4 5 Doctor 6 Dr Smith 7 Dr Lam 8 Mrs Dapper 9 Prof. Plum 10 11 Selection for month of:
May
www.MeadInKent.co.uk

G
2

3 Out Patient visits

Month number

Month 1 Month 2 Month 3 Selection Cumulative 63 41 3 135 61 42 43 123 62 48 40 115 61 42 43 123 124 83 46 258

[G3] = 2 [G6:G9]=OFFSET($C6,0,$G$3)

2 61

the user can type a value of 1, 2 or 3 in this cell get the value in the cell 0 rows and 2 columns away from C6 add up cells in the range starting 0 rows and 1 column away from C6. The range is 1 row deep and 2 across

[H6:H9]=SUM(OFFSET($C6,0,1,1,$G$3)) 124 [E11]=CHOOSE(G3,"Apr","May","Jun")

May Select the 2nd item in the list of text month names
formulae used in example

The OFFSET and CHOOSE functions in this example both make use of the value typed into cell G3 (currently 2). The formula in the 'Selection' column is straight forward and just reads a single value each time. The 'Cumulative' column (H) is more complex. The OFFSET function returns a range of cells one row tall and 2 columns wide (D6:E6) which alone means nothing and would generate an error. However, when it is supplied as the range argument to a function such as SUM() it becomes very useful.

Вам также может понравиться