You are on page 1of 42

Advanced Excel

17-11-2015

AE- Miguel Campos

COURSE OUTLINE
1. Names
2. Formulas Audition & Calculation

3. Functions Review Statistical, Text, Math, Information


4. Advanced Functions Review
Conditional Statistical, lookup functions & Dynamic References

4. Advanced Filtering & Removing Duplicates


5. Advanced Data Validation & Conditional Formatting

6. Basic Array Formulas


7. Advanced Array Formulas
8. Problem Solving with Solver
17-11-2015

AE- Miguel Campos

CELL CONTENT
A) DATA
1) Numbers

123

2) Dates

Number of days between 1/1/1900 and MyDate

3) Logical

True

4) Errors

#N/A #Value! #REF!

5) Text

12.5 is text

12,5 0,25

(depends on Regional Settings)

False

Numbers or dates following is text

B) FORMULAS
Start with = (or +)
Text in Formulas should be between quotes: 12 Lisboa

Always return at least one value


17-11-2015

AE- Miguel Campos

FORMULAS
HOW TO INSERT A NEW FORMULA

1) Using the Formula Menu

1) Typing the formula in the Manu Bar

2) Using The Insert Function Wizard

3) Typing the formula directly into the cell

17-11-2015

AE- Miguel Campos

FORMULAS
HOW TO CHECK AN EXISTENT FUNCTION
Using The Insert Function Wizard

HOW TO INSERT A FUNCTION INSIDE ANOTHER FUNCTION IN THE WIZARD


Using The Insert Function Wizard

17-11-2015

AE- Miguel Campos

FORMULAS
Cell References
1. Relative Cell References
Excel, by default, uses a reference format known as A1

ex: F5

References contain a combination of both the column letter and row number

2. Absolute Cell References


In order to not change reference cells when copying formulas from one cell to
another, reference cells should be blocked with the symbol $

ex: $F5 ; $G$6

Use key F4 to block cells with $

3. Range References
A1:C5

15 cells starting in A1 and finishing at C5

A1:C5 ; D6:E7

all cells from 2 ranges

1:2

all cells from rows 1 and 2

C:E

all cells from columns C, D and E

sheet2!A1:C5
17-11-2015

all cells in sheet2 starting in A1 and finishing at C5


AE- Miguel Campos

FORMULAS
Operations inside formulas are executed in the following order:

1) What is inside parentheses


2) Functions
3) Numerical Operators

3.a) ^
3.b) * , /
3.c) + -

4) Concatenation Text Operator: &


5) Relational Operators: = <> > >= < <=

return TRUE| FALSE

6) From left to right (when the priority is equal)


17-11-2015

AE- Miguel Campos

FORMULAS
Cell References
1. Relative Cell References
Excel, by default, uses a reference format known as A1
References contain a combination of both the column letter and row number

2. Absolute Cell References


In order to not change reference cells when copying formulas from one cell to
another, reference cells should be blocked with the symbol $
Use key F4 to block cells with $

3. Range References
Upper Left Cell reference : Lower Right Cell reference
ex: A1:C5
17-11-2015

AE- Miguel Campos

FORMULAS
AUDITION
1) Using F2 Key

2) Formula Auditing Menu

17-11-2015

AE- Miguel Campos

FORMULAS
CALCULATION
1) Automatic (default)

2) Manual

17-11-2015

AE- Miguel Campos

10

Defining NAMES
A NAME

is a meaningful shorthand that makes it easier to understand the


purpose of a cell reference, constant or formula

17-11-2015

AE- Miguel Campos

11

Defining NAMES
Rules:
1) a name should start with a letter or _
2) afterwards can be letters, numbers or _
3) spaces are not allowed
4) a name cant be a cell or range reference

17-11-2015

AE- Miguel Campos

12

FUNCTIONS
EXCEL FUNCTIONS:
1) have a name and parameters between parenthesis
2) always return at least one value: number, date, text, True|False, #N/A, #Value!, ..
A) TEXT
Left, Right, Mid
Left(Mary Ann, 2) -> Ma Mid(Mary Ann; 3; 5) -> ry An
Exact, Len
T = t -> True Exact(T, t)->False Len(Mary Ann) -> 8
Trim, Concatenate
Trim( Mary Ann ) -> Mary Ann
Upper, Lower, Proper
Upper(Mary 9) -> MARY 9 Proper(mary ann) -> Mary Ann
Find, Search
Search(a; Ana)-> 1 find(a; Ana)-> 3 find(b; Ana)-> #Value!
Substitute
Substitute(Ana Maria ; ; ) -> AnaMaria
Text( , format)
Formats: "000" ; "00.00"; "###"; "yyyy-mm-dd
Char, Code
code(A) -> 65 char(65)->A
B) DATE
Today, Now
Today(), Now()
Weekday, Weeknum
Year, Month, Day
Date , Time
Date(1985; month(today()); day(today()))
Datedif
Datedif(oldDate; NewDate,;y")
17-11-2015

AE- Miguel Campos

13

FUNCTIONS
C) MATH
Sum, Product
Int, Trunc
Round , Roundup, RoundDown
Ceiling; Mround
Mod, Quotient, Sqrt, Power, Pi
Rand, RandBetween
SumSQ
SumProduct
SumX2MY2
D) STATISTICAL
Average, Stdev, Var, Avedev
Mode, Median
Max, Large
Min, Small
Rank
Count, CountA, CountBlank
17-11-2015

product(3; 5; 4) -> 60
int(-4,6) -> -5 trunc(-4,6) -> -4
RoundUP(18,4; 0) -> 19 RoundDown(18,4; 0) -> 18

Ceiling(13;4) -> 16

MRound(13;4) -> 12

Mod(7;2) -> 1 Quotient(7;2) -> 3 Pi() -> 3.14259


Rand() -> [0..1[
SumSQ(1;2; 2;3) -> 18

SumSQ({1;2}; {2;3}) -> 18

Sumproduct({1;2}; {2;3}) -> 8


SumX2MY2({1,2}, {2,3}) -> -8

stdev(3; 5;4) -> 1

avdev(3; 5; 4) -> 0.667

mode(3; 5;4;5) -> 5


large(range1; 2)
Sum(small(A1:B3;{1;2}))
Rank(15;E17:E18;0) -> position in desc order

AE- Miguel Campos

14

FUNCTIONS

17-11-2015

AE- Miguel Campos

15

FUNCTIONS
E) MATH & STAT with Conditions
Countif, CountIfs
SumIf,
SumIfs
Averageif, AverageIfs

averageifs(rangeF; range1; >=10; range2; T1)


averageifs(rangeF; range1; >= & average(range1) )

Criteria:
1) should always be text
2) if there is a need to calculate a value use operator &: >= & average(range1)
3) dont use AND( ), OR() as criteria
4) only for multiple AND conditions; not for multiple OR conditions
5) "a*" - rows with text started with an "a"
6) "*a" - rows with text finishing with an "a"
7) "*a*" - rows with text at least with an "a"
8) "a?" - rows which text start with an "a" followed by one letter
9) "?a*" - rows which text has an "a" as second letter
17-11-2015

AE- Miguel Campos

16

FUNCTIONS

17-11-2015

AE- Miguel Campos

17

FUNCTIONS
F) INFORMATION
isError
isblank, IsNumber, istext
G) LOGICAL
And, Or, Not

#N/A, #NUM!, #REF!, #VALUE!

all functions always return True | False

And( A1 > 2; A2 <> 3)


Or(not(A1 > name2); A1> 3)
Allways return True|False

If

if( test, actionTrue, actionFalse)


if(isnumber(A1); 1; -1)
if(test1, actionTrue, if(test2,;action2True; action2False)
if(D1>10; Pass; if(D1 > 8; Exam; FAIL))

Iferror

iferror( expression, action_iferror)


iferror(find(DIRECT; B1), )

H) DYNAMIC REFERENCES (Lookup functions)


Indirect
indirect(D1) and D1= A1:C5
Offset
average(offset(A1; 0; 0; 2; 3)) Average(A1:C2)
Address
Address(37,2,4,,"sheet1") -> sheet1!B37
17-11-2015

AE- Miguel Campos

18

FUNCTIONS

17-11-2015

AE- Miguel Campos

19

FUNCTIONS
I) LOOKUP Functions
Row, Column
Rows, Columns

row(B5) -> 5
rows(5:6) -> 2

columns(A:B) -> 2

Match

returns the position of an element Z


match(3; {2;3;5;3} ; 0) -> 2
match(3; {2;3;5;3} ; False) -> 2
match(4; {2;3;5;3} ; 0) -> #N/A
match(4; {2;3;5;3} ; 1) -> 2

Index

returns an element in position X (or X, Y)


index({2;3;5;3} ; 2) -> 3
index({2;3;5;3} ; 2; 1) -> 3
index({2;3;5;3} ; 20) -> #REF!
index({2,3,5,3 ; 1,2,3,4}, 0, 1) -> 1st column {2;1}

Vlookup

vlookup(myValue; myTable; colNumber; 0)


returns a value from MyTable and column colNumber in the
same row where it finds myValue in the first column
(-) only useful when the table first column is the search column
(-) only useful when the data is in a single table

Index( ;Match( ; ; 0))

(-) it is not a function thus it does not exist on the wizard

17-11-2015

AE- Miguel Campos

20

FUNCTIONS
J) ARRAY Functions
Functions that return multiple values and not a single one
Steps:
1) Select all cells
2) Write the formula (start with =)
3) Press Ctrl+Shift+Enter
Afterwards the formula should be surrounded by curly brackets
Examples:
Transpose, MInverse
MMult
Frequency
Large
Small

17-11-2015

{=transpose( range1)}
{=mmult( range1; range2)}
{=frequency( range1; {1,2,3,4})}
{= large(range1; {1;2}) }
{= Sum(small(A1:B3;{1;2}))}

AE- Miguel Campos

21

CONDITIONAL FORMATING
Format cells according to their own values
Choose a predefined conditional formatting option

Format cells according to other cell values


Choose Manage Rules/New Rule/Use a formula
Steps
1) Select the cells to format
2) Start the formula with =
3) The formula should always return True or False
Be careful with using the IF function
4) Do the formula for the first cell, row or column
on the background excel will copy it
5) Define the format to apply
Stop If True option: excel will stop to evaluate more conditions

17-11-2015

AE- Miguel Campos

22

DATA VALIDATION
Deny entering certain values
Whole numbers, Decimals, Date, Time, Text length

Deny entering certain values based in a formula


Custom

type the formula for the first cell ex: =(Mod(A2; 3) = 0)


excel copies the formula from the first cell to the others

Allow only a fixed number of values


List
List of values :
Range
:
Dynamic Range :
Lists in cascade:

1; 2 ; 3
=A1:A7
=Offset(A1; 0;0;2;1)
=range1
List1
=indirect(name in cell) List2

Error Alert message : the message to give the user in case of error
17-11-2015

AE- Miguel Campos

23

ADVANCED FILTERING

17-11-2015

AE- Miguel Campos

24

DUPLICATED DATA

1) Formatting Duplicates

2) Removing Duplicates
3) Filtering Duplicates
4) Moving Duplicates and Unique Data to other places

17-11-2015

AE- Miguel Campos

25

ARRAY FORMULAS
Why the need of array formulas?
1) There are some operations we cannot do without auxiliary columns:
Maxifs
Averageifs
sumifs
Averageifs

but ignoring the errors


with multiple OR criteria
calculating a formula in each row value where to apply a condition
ex: average sales of oranges at Saturdays

2) We can do with one array formula what we need to do with N formulas


{=randbetween(1;50)} =randbetween(1;50) .. =randbetween(1;50)

3) There are some operations that can only be done with Macros and CSE
Dynamically sort ranges

17-11-2015

AE- Miguel Campos

26

ARRAY FORMULAS
What is an Excel array formula?
1) An array formula return several values instead of just one or
2) An array formula return a single value but implied the creation and use of at
least one virtual range
= Sum(A1; A3; A4)
-> Regular Formula
{= A1:A4 * B1:B4}
-> Array Formula
{=Max(A1:A4 * B1:B4) } -> Array Formula

17-11-2015

AE- Miguel Campos

27

ARRAY FORMULAS
Array formulas are created by pressing the Ctrl, Shift, and Enter keys on the
keyboard at the same time once the formula has been typed in. They are
sometimes referred to as CSE formulas.
After pressing Ctrl-Shift-Enter the formula bar displays braces (curly brackets)
around the formula. Ex: {= A1:A4 * B1:B4}
Use the F9 key to evaluate portions of an array formula
ex: {=sum(if(A1:A4<4,A1:A4))} ->'=SUM({3;4;FALSE;FALSE})

To create a column array of constants, type the values separated by commas and
enclose them in braces, for example {1;2;3;4}. To create a row array of constants,
type the values separated by commas, for example {1,2,3,4}
To dynamically create a range of values in your CSE formula use the functions
row() or column(). For example
{=ROW(1:9)}
{=COLUMN(1:9)}
17-11-2015

returns the column {1;2;3;4;5;6;7;8;9} {row(1); row(2);..; row(9)}


returns the row {1,2,3,4,5,6,7,8,9}
AE- Miguel Campos

28

ARRAY FORMULAS
Types of Array Formulas
1) MULTI-cell Array Formulas - formula entered in a range of cells. It returns several values.
{= A1:A4 * B1:B4}

2) SINGLE-cell Array Formulas - formula entered in a single cell although it processes ranges
of cells
{=MAX(A1:A4 * B1:B4) }
3) Excel Array Functions - There exist a few Excel array functions that are designed to
return multi-cell arrays
FREQUENCY, TRANSPOSE, TREND, MINVERSE, MMULT

17-11-2015

AE- Miguel Campos

29

ARRAY FORMULAS
OPERATORS since they expect a fixed number of parameters
-> they can be used to create an intermediate virtual range!!
1. ARITMETIC: +, -, *, /, ^
{={1;2;3} + {3;2;1}}
{={1;2;3} * {3;2;1}}

-> {4; 4; 4}
-> {3; 4; 3}

2. TEXT: &
{={1;2;3} & {3;2;1}}

-> {13; 22; 31}

3. RELATIONAL: =, <>, >, >=, <, <=


{={1;2;3} = {3;2;1}}
{={1;2;3} <> {3;2;1}}
{={1;2;3} >= {3;2;1}}

17-11-2015

-> {False; True; False}


-> {True; False; True}
-> {False; True; True}

AE- Miguel Campos

30

ARRAY FORMULAS
Functions that expect a fixed number of parameters
-> they can be used to create an intermediate virtual range!!
1. IF, IFERROR
{=If( {True; True; False; True}, 5, 10)}
{=IF({1;1;0;1}, {1;3;5;7}, {2;4;6;8})}
{=IF( {7;3;6;7}>3; 1; 0)}
{=Iferror( {7; #VALUE!; TRUE; #REF!}, "")

-> {5;5;10;5}
-> {1;3;6;7}
-> {1;0;1;1}
-> {7;;True;}

2. ABS, SQRT, COS, LEN, NOT


{=Abs( {-16; 4; -25} )}
{=Sqrt( {16; 4; 25} )}
{=Len({ANA; LISBOA; PARIS})}
{=Not( {False; True; False} )}

-> {16; 4; 25}


-> {4; 2; 5}
-> {3; 6; 5}
-> {True; False; True}

3. COUNTIF, MATCH
{=countif({1;2;1}; {1;2;1})}
(how many times appears each element)
{=match({1; 3; 3; 2}, {1; 3; 3; 2}; 0} (first position of each element)

-> {2;1;2}
-> {1;2;2;4}

4. LARGE, SMALL
{=large({1;2;3}; {1;2})}
17-11-2015

-> {3; 2}
AE- Miguel Campos

31

ARRAY FORMULAS
Functions that expect several parameters and only return one value..
-> they cannot be used to create an intermediate virtual range!!
but they can be used for the final calculation in an array formula.

A. SUM, AVERAGE, MAX, MIN, MODE

{=sum({1;2;3} ; {3;2;1})}

-> returns 12 and not {4;4;4}

NOK

This expression excel will evaluate as => sum(1;2;3;3;2;1)

{=max({1;2;3} ; {3;2;1})}
{=average({1;2;3} ; {3;2;1})}

-> returns 3 and not {3;2;3}


-> returns 2 and not {2;2;2}

NOK
NOK

but

{=average({1;2;3} * {3;2;1})} -> 3.333


{=average(abs({-1;2;-3} ))} -> 2

OK
OK

B. AND, OR
{=And({7;12;10} >=10; {9;7;15} >=10)} -> returns False and not {False; False; True}
{=Or({7;12;10} >=10; {9;7;15} >=10)} -> returns True and not {False; True; True}

NOK
NOK

Excel will evaluate this expression as => Or( 7>=10; 12>=10; 10>=10; 9>=10; 7>=10; 15>=10)
17-11-2015

AE- Miguel Campos

32

ARRAY FORMULAS
How to work with multi-cell array formulas
1.
2.
3.

4.
5.

6.

Select the range of cells where you want to output the results before entering
the formula.
To delete a multi-cell array formula, either select all the cells containing it and
press DELETE
You cannot edit, move or delete the contents of an individual cell in an Excel
array formula. Nor can you insert new cells into or delete existing cells from a
multi-cell array formula.
To shrink an array formula, i.e. to apply it to fewer cells, you need to delete
the existing formula first and then enter a new one.
To expand an array formula, i.e. apply it to more cells, select all cells
containing the current formula plus empty cells where you want to have it,
press F2 to switch to the edit mode, adjust the references in the formula and
press Ctrl + Shift + Enter to update it.
If an array returned by the formula is smaller than the selected range, #N/A
errors will appear in extra cells.
17-11-2015

AE- Miguel Campos

33

ARRAY FORMULAS
Examples of basic Array Formulas
1. The sum of the absolute value of each item in a list.
{=SUM(ABS(A1:A5000))}
2. Find the smallest non-zero value in a set of values.
{=MIN(IF(A1:A5000<>0; ABS(A1:A5000)))}
3. To count the number of cells that contain an error value.
{=SUM(IF(ISERROR(A1:A5000);1;0)}
4. Sum ignoring errors
{=SUM( IF(ISERROR(A1:A9); 0; A1:A9) )}

Normally SUM propagates any error found

5. Average of the three smallest values of a range.


{=AVERAGE( SMALL(Range1; {1;2;3})
6. Maximum sales in a particular month.
{=MAX(IF(MONTH(Range4)=5; Sales; 0))}

Max Sales in May

7. How many unique elements in a column


{=SUM(IF(COUNTIF (C2:C9; C2:C9)=1 ; 1; 0))}
17-11-2015

AE- Miguel Campos

34

ARRAY FORMULAS
Statistical Functions with Multiple Conditions
AND : cannot be used -> we should use multiplication
OR : cannot be used -> we should use addition

*
+

CAUTITION: parentheses surrounding each condition

17-11-2015

AE- Miguel Campos

35

ARRAY FORMULAS
Statistical Functions with Multiple Conditions
8.

Average of entries matching multiple AND conditions.


{=AVERAGE(IF (Range1="red")*(Range2="big"); Range3)}

9.

Count of entries matching multiple AND conditions.


{=SUM( (Range1="red")*(Range2="big"))}

10. Average sales with multiple calculated AND conditions.


{=AVERAGE(IF((MONTH(Range4)=5) * (LEFT(Range1)=R) * (Sales>100); Sales))}
11. Count of entries matching multiple OR conditions.
{=SUM(IF((Range1 ="red")+(Range2 ="big") ;1;0)}

12. Count rows that fulfill at least 2 conditions in 3.


{=SUM(IF(((exam1<10)+(exam2<10)+(exam3<10))>=2; 1; 0))}
13. Average Sales if neither Cond1 nor Cond2 are meet.
{=AVERAGE( if(NOT((Range1 ="red")+(Range2 ="big")); Sales;)}

17-11-2015

AE- Miguel Campos

36

ARRAY FORMULAS
Returning Single/Multiple Matches Values
13. The name with more chars in a list of names
{=INDEX(B2:B9; MATCH(MAX( LEN(B2:B9 )); LEN(B2:B9); 0)) }

-> return a single value

14. The two names with more letters in a list of names


{=INDEX(B2:B9; MATCH(LARGE( LEN(B2:B9 ); {1;2}); LEN(B2:B9); 0))}

-> return several values

15. Which number in the range Sales is closest to a specified number XXX.
{=INDEX(Sales; MATCH(MIN(ABS(Sales XXX)), ABS(Sales - XXX),0))}

-> return a single value

16. Class with more students


{=INDEX(ClassRange, MATCH(MAX(COUNTIF(ClassRange, ClassRange)), COUNTIF(ClassRange,
ClassRange), 0))}
-> return a single value

17-11-2015

AE- Miguel Campos

37

ARRAY FORMULAS
Returning Single/Multiple Matches Values
17. Get the names when some conditions are verified
{=IFERROR(INDEX(Names, SMALL(IF((exame1>10) * (exame2>10)>0, ROW()-1, ""), ROW(names)1)), )}
-> student names when they have exam1>10 AND exam2>10

18. Get the names based on a lookup value


{=IFERROR(INDEX(names; SMALL(IF(animals=E1; ROW()-1;""); ROW(names)-1));"")}

17-11-2015

AE- Miguel Campos

38

ARRAY FORMULAS
Returning Single/Multiple Matches Values
19. Get values without duplicates from a list of values
{=INDEX(animals; SMALL((IF(MATCH(animals; animals;0)=Row(); Row();""); Row(animals)))
we store on our artificial range the row numbers where each element appears the first time

20. Sort dynamically a list of numbers


{=SMALL(Range; Row(Indirect("1:" & Rows(Range))))}

21. Sort dynamically a list of text values


{=INDEX(list; MATCH(SMALL(Countif(list; "<" & list); ROW(Indirect("1:" & Rows(list))) );
COUNTIF(list; "<" & list); 0))}

17-11-2015

AE- Miguel Campos

39

ARRAY FORMULAS
Array Formulas Optimization
1. Multiplication by 1 when array of booleans to sum

Ex: {=sum( if(A1:A9 > 10; 1; 0))} {sum((A1:A9 >10)*1)}

2. Sumproduct

Can be used to sum values of ranges (or sum values from one range)
It is not an array formula
It is 10%-15% faster
Ex: = sumproduct((A1:A9 >10)*1)

1. Index( ;0)

We can transform an array formula in a conventional formula using


index(;0)
Conditional formatting and Data Validation dont accept Array Formulas

17-11-2015

AE- Miguel Campos

40

PROBLEM SOLVING - SOLVER

17-11-2015

AE- Miguel Campos

41

PROBLEM SOLVING - SOLVER


1) GOAL cell with a formula

2) WHAT TO CALCULATE cells without formulas


3) MODEL

If we are calculating decisions to make we should create a binary column

The only cells without formulas in our model is XXX

4) CONSTRAINTS

Decisions should be binary

Products, - should be integer

5) SOLVER OPTIONS

Number of iterations

Method Used

17-11-2015

AE- Miguel Campos

42

You might also like