Useful Formulas For Use in MS Excel

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Useful formulas for use in MS Excel

1. 2. 3. 4.

Dividing two numbers to get the product in pounds, shillings and pence Separating two strings bounded by a comma Using conditional statements Counting within a list delimited by sequential numbers

1. Dividing two numbers to get the product in pounds, shillings and pence
A 1 2 St. Marylebone 3 St. Pancras 4 St. George's, Hanover Square 5 Islington B Persons 161860 198788 87771 155341 C Houses 16357 21852 10437 20704 D RV 1053748 925872 1076722 777632 E F G

To get the rateable value (RV) per person in pounds and shillings and pence, use the following three formulae in cells E2, F2, and G2: E2: =SUM(INT(D2/B2)) F2: =INT(SUM((D2/B2)-E2)*240/12) G2: =INT(SUM(((D2/B2)-E2-(F2/240*12)))*240) The formula for cell E2 gives the product of the division between the rateable value rounded down (using the function INT) to the nearest whole number. The formula in cell F2 takes the remainder of the previous sum, converts it to pennies, by multiplying by 240 and then divides by 12 to get shillings. Again an integer is given, rounding the whole number down. The formula in G2 repeats the calculations in F2 leaving a fraction of a pound which when multiplied by 240 gives the number of pence.

2. Separating two strings bounded by a comma


A NAME 1 Davies, Peter 2 Davis, Hezekiah B C

To separate the two elements of this variable use the following formulae in cells B1 and C1: B1: =LEFT(A1, FIND(",",A1)-1) C1: =RIGHT(A1,(LEN(A1)-FIND(",",A1)-1)) The LEFT and RIGHT functions are used to truncate a string, starting either from the left of that string or the right. The form is LEFT(string, number) where string is the cell you are interested in and number is the number of characters you want to take from that string. Thus =LEFT(shillings, 1) returns s. The second function used here is FIND. This function finds the character given in its first argument in the string given in its second argument. Thus =FIND(s, pounds) will return the number 6. Note that the FIND function only returns the character position of the first occurrence of that character. The first of these formulae then first finds the position of the comma in the string. (In the first case this is position 7. Then it truncates, from the left, a total of 6 characters (7 minus 1). This is necessary here because we dont want the comma to appear in our result. The second of these formulae first finds the total length of the string, using the LEN function. Then finds the position of the comma. The latter number is subtracted from the first finding the length of the string after the comma. Because there is a space after the comma in both examples we remove one fewer character. The resulting number is used as part of the RIGHT function which takes the number of characters in its second argument from the right hand side of the first argument.

3. Using conditional statements Excel allows one to perform rudimentary conditional statements. Consider the census enumerators books where originally data relating to sex was denoted by being placed in the age columns:
A 1 2 3 4 5 Frederick Florence Violet Ethel Michael Skipper Skipper Skipper B Skipper C Head Wife Daughter Daughter Son 4 43 12 11 D E AGE_M F AGE_F

Here we know that Frederick Skipper is male because his age is recorded in the Male column. Suppose that we wanted to add a column which gave the sex of each of these people, we would use the IF function. In cell G1 we would use the following formula: =IF(E1>0,"M","F"). This is saying that if the contents of the cell E1 (which is the male age) is greater than 0 then this person is a male and return the string M, otherwise (i.e., if the contents of E1 is less than 0 or missing) then return the string F. This is not entirely foolproof, because if the contents of the column for AGE_M contains anything at all, like a dash, it will return M. The basic syntax of the IF statement can be summarised as =if(condition is fulfilled, something, otherwise something else). IF statements are particularly useful because they can be nested. Nesting a condition, allows one to ask many (up to seven) conditions within a single statement. In the following example let us suppose that we want to classify the seven districts in Cornwall according to their population density. In our classification we want to have three groups, those districts which have a population density of less than one person per acre; those which have a population density of between one and five persons per acre and third, those which have a density of over five persons per acre.
A 1 2 3 4 5 6 7 Bomin MB Bude-Stratton Camborne-Redruth Falmouth Fowey MB Helston MB Launceston MB B Acres 3312 4294 22062 1880 2979 4014 2182 C 5514 4459 34920 15040 2255 4939 4273 D 1.66 1.04 1.58 8.00 0.76 1.23 1.96

Population Density

=IF(D4<1,"GROUP1",(IF(D4<5,"GROUP2", "GROUP3")))

Consider the statement in stages: =IF(D4<1,GROUP1, ANOTHER GROUP) allows us to use two groups. Either the density is less than one or it isnt. If it is the formula will return GROUP1 otherwise it will return ANOTHER GROUP. So rather than ask Excel to return the string ANOTHER GROUP for all those districts which have a density of 1 or greater, we can nest a further IF statement. On its own this nested statement would look like this: =IF(D4<5, GROUP2, GROUP3). Here if the density is less than 5 Excel will return GROUP2 otherwise GROUP3. Putting the two together is like saying: if the contents of cell D4 is less than 1 return GROUP1, otherwise, first check to see whether its also less than 5, if it is then return GROUP2, and then for all others return GROUP3.

4. Counting within a list delimited by sequential numbers This series of formulae show how one can add the total number of people in a household to a spreadsheet based on census enumerators' books which only contains schedule numbers. The method can be employed for counting other lists of material which are delimited by sequential numbers.
A B 1 2 1 MARY 3 4 5 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 27 28 JAMES JAMES ANN ELLEN MARY ANN CATHERINE ELIZA THOMAS ELIZABETH MARY ANN JOSEPH THOMAS? BETTY JOHN JANE FANNY CATHARINE FANY CAROLINE ELLEN MARY A MARY G GREAVES DO WARD CHESHIRE PICKTON DO DO DO DO DUCKWORTH DO DO DO ROYLE? DO LOWTON FOULKES? DO GARDY? WATTS DO DO DO WILKINSON FURNIVAL? DO DO BEAUMONT DOBSON DO DO FLETCHER HEAD SON SERV DO HEAD WIFE NEICE DO DO HEAD SON DAUR IN LAW GRANDDAUR LODGER DO DO DO DO DO HEAD WIFE DAUR DO SERV HEAD NEICE GRAND DAUR HEAD HEAD WIFE DAUR STEP DAUR C D E F G H

6 2 ISAAC

11 3 MARY

21 4 JOSEPH

26 5 LYDIA

29 6 WILLIAM 30 7 ROBERT 31 32 33 ELIZABETH MARGARET JANE

Column A contains the schedule number; columns B and C contain the personal name and column D contains the relationship to household head. Note that the first row of this spreadsheet is empty.

Step one: Allocating a household number to each individual First, ensure that the first row of the table is empty. Type into cell E2 =IF(A2>=1,A2,E1) and then copy down to the end of the column. This checks whether the "schedule" number in column A is present or not. If it is present, then that number is put into column E; if it is not then the number directly above is inserted. Step two: Allocating a sequential household number In cell F2 insert the following formula: =IF(E2-E1=1,1,F1+1). This adds a sequential personal identifier for each member of the household. Step three: removing household numbers Insert =IF(F2>=F3,F2,0) into cell G2 and copy down to the end of the table. This allocates the total number of people in the household to the last person only, all others get the value of 0. Step four: putting the highest household number to all records in the household Putting the formula =IF(F2=G2,G2,H3) into cell H2. This adds the total number of people in each household to all the household members. Note: If using OpenOffice Calc replace the commas in the if statements with semicolons.

You might also like