0% found this document useful (0 votes)
34 views

Modules in Excel Part2

The document discusses the Excel VLOOKUP function and related functions COUNTIFS and COUNTIF. It provides detailed explanations of the syntax and arguments for each function as well as examples of how to use wildcards and logical operators. The key points are: - VLOOKUP looks up values in a table based on a search value and returns a value from the same row in a specified column number. It only searches left to right. - COUNTIFS counts cells that meet multiple criteria across multiple ranges, while COUNTIF counts cells that meet a single criteria in one range. - Wildcards like * and ? can be used with VLOOKUP and COUNTIF to find partial matches. Logical

Uploaded by

racelgenshin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Modules in Excel Part2

The document discusses the Excel VLOOKUP function and related functions COUNTIFS and COUNTIF. It provides detailed explanations of the syntax and arguments for each function as well as examples of how to use wildcards and logical operators. The key points are: - VLOOKUP looks up values in a table based on a search value and returns a value from the same row in a specified column number. It only searches left to right. - COUNTIFS counts cells that meet multiple criteria across multiple ranges, while COUNTIF counts cells that meet a single criteria in one range. - Wildcards like * and ? can be used with VLOOKUP and COUNTIF to find partial matches. Logical

Uploaded by

racelgenshin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Excel VLOOKUP Function

The VLOOKUP Function (which stands for "vertical lookup") is one of the most useful functions
in Excel, and is a fast way to look up a value when your information is arranged in a table with
rows and columns. The VLOOKUP function has four arguments (values in the function separated
by commas) and because of this people often think VLOOKUP is complex. Once you try a few
practice problems with VLOOKUP you'll see how simple it really is.

Syntax of the VLOOKUP Function

If your data is arranged in a table with rows and columns, the VLOOKUP function will tell you a
value in one row if you know a different, corresponding value to the left in that same row (the
VLOOKUP function only looks from left to right). For the VLOOKUP example below, say you have
a table with columns for employee ID, hire date, and employee name in your Excel spreadsheet,
as shown in the image below. Each row represents a different employee. Say you want to retrieve
the name of the employee with ID 1234 using VLOOKUP.

=VLOOKUP(lookup_value, lookup_range, column_number, [approximate_match])

1. Lookup_value: This is the value that you know, which you will use to locate the value that
you do not know. In this example it is the employee ID, which is 1234
2. Lookup_range: This is the entire table, also called the lookup table or table array, that
we are searching. We could say A1:C6. If this was a long list we could use the entire
columns A:C
3. Column_number: The columns in your lookup_range table are numbered from left to
right, starting with 1. The VLOOKUP function will locate the lookup_value in column 1 (far
left) and return the value in the same row but in the column specified by column_number.
The employee ID column is 1, the hire date column is 2, and the employee name column
is 3. Note that VLOOKUP only searches from left (starting in column 1) to right. Because
we want VLOOKUP to return the employee's name, we will specify 3 for column_number.
4. Approximate_match: This is the only optional argument, though it's recommended that
you specify it as false (it defaults to true) when you know the lookup_value. In our case
we can say false or 0; we want an exact match on 1234. The default value is true, so if
you leave this blank Excel will tell VLOOKUP will look for approximate matches, which we
typically don't want except for special cases.

So, in order to use the VLOOKUP function in Excel to find the name of the employee whose ID is
1234, you could use the formula =VLOOKUP(1234, A1:C6, 3, false). See image below for details.
Note that the value you know (the first argument) must always be in the first column (on the far
left side) of the range you choose.

VLOOKUP With Wildcard Matching


Excel lets you use the VLOOKUP function with wildcards. Note that this only works in exact
matching mode, so your fourth argument (approximate_match) must be 0 or FALSE. Remember,
you can't omit this argument because Excel defaults approximate_match to true. Also note that
this only works for matching strings of text.

What is Wildcard Matching in Excel?

Wildcard matching in Excel is the ability to use characters which represent anything in a string of
text. For example, say you know someone's first name but not their last name. You could find this
person in an Excel spreadsheet by concatenating their first name with a wildcard character.

A question mark (?) replaces exactly one character in a string of text in Excel.

An asterisk (*) replaces any number of characters in a string of text in Excel.

To use a wildcard in Excel, you concatenate an asterisk enclosed in quotes at the beginning or
end (or both) of your string of text. It looks like this:
=VLOOKUP("My text"&"*", A:C, 2, FALSE)

The VLOOKUP function will then return the first value it finds where the lookup_value is text that
begins with "My text". If our lookup_value was instead "*"&"my text", then it would search for any
text that ends with "my text" because the asterisk comes first.

A B C

1 Employee Name Employee ID Hire Date

2 Will Ferrell 2323 1/1/2019

3 John C. Reilly 1020 10/8/1992

4 Sacha Baron Cohen 1234 12/10/2005

5 Amy Adams 5555 5/10/2000

6 David Koechner 5816 1/20/2011

Say we want to find the ID number of the employee whose first name is "Amy". We could use the
wildcard match as follows:

=VLOOKUP("Amy"&"*", A:B, 2, FALSE)

This will return the ID number of the first employee in the table whose name starts with the text
"Amy". Now suppose you want to find the ID of the employee whose middle initial is C. You can
use wildcard at the beginning and end of the search string as follows:

=VLOOKUP("*"&"C."&"*", A:B, 2, FALSE)

This will return the ID of the first employee who has "C." in their name.
COUNTIFS and COUNTIF

Of all Excel functions, COUNTIFS and COUNTIF are probably most often mixed up because they
look very much alike and both are purposed for counting cells based on the specified criteria.

The difference is that COUNTIF is designed for counting cells with a single condition in one range,
whereas COUNTIFS can evaluate different criteria in the same or in different ranges.

COUNTIF is an Excel function to count cells in a range that meet a single condition. `COUNTIF
can be used to count cells that contain dates, numbers, and text. The criteria used in COUNTIF
supports logical operators (>,<,<>,=) and wildcards (*,?) for partial matching.
Use COUNTIF, one of the statistical functions, to count the number of cells that meet a criterion;
Syntax
=COUNTIF(range, criteria)
Arguments

• range - The range of cells to count.


• criteria - The criteria that controls which cells should be counted.

The COUNTIF function counts cells in a range that meet a given condition, referred to as criteria.
COUNTIF is a common, widely used function in Excel, and can be used to count cells that contain
dates, numbers, and text. Note that COUNTIF can only apply a single condition.

Applying criteria

The COUNTIF function supports logical operators (>,<,<>,<=,>=) and wildcards (*,?) for partial
matching. The tricky part about using the COUNTIF function is the syntax used to apply criteria.
COUNTIFS is in a group of eight functions that split logical criteria into two
parts, range and criteria. Because of this design, each condition requires a
separate range and criteria argument, and operators in the criteria must be enclosed in
double quotes (""). The table below shows examples of the syntax needed for common criteria:
In the worksheet shown above, the following formulas are used in cells G5, G6, and G7:

=COUNTIF(D5:D12,">100") // count sales over 100


=COUNTIF(B5:B12,"jim") // count name = "jim"
=COUNTIF(C5:C12,"ca") // count state = "ca"

Notice COUNTIF is not case-sensitive, "CA" and "ca" are treated the same.
Double quotes ("") in criteria

In general, text values need to be enclosed in double quotes (""), and numbers do not.
However, when a logical operator is included with a number, the number and operator
must be enclosed in quotes, as seen in the second example below:

=COUNTIF(A1:A10,100) // count cells equal to 100


=COUNTIF(A1:A10,">32") // count cells greater than 32
=COUNTIF(A1:A10,"jim") // count cells equal to "jim"

Not equal to

To construct "not equal to" criteria, use the "<>" operator surrounded by double quotes
(""). For example, the formula below will count cells not equal to "red" in the range
A1:A10:

=COUNTIF(A1:A10,"<>red") // not "red"

Blank cells

COUNTIF can count cells that are blank or not blank. The formulas below count blank
and not blank cells in the range A1:A10:

=COUNTIF(A1:A10,"<>") // not blank


=COUNTIF(A1:A10,"") // blank

Note: be aware that COUNTIF treats formulas that return an empty string ("") as not
blank. See this example for some workarounds to this problem.
Excel COUNTIFS function - syntax and usage
The Excel COUNTIFS function counts cells across multiple ranges based on one or several
conditions.

COUNTIFS syntax

The syntax of the COUNTIFS function is as follows:

COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)

• criteria_range1 (required) - defines the first range to which the first condition (criteria1)
shall be applied.
• criteria1 (required) - sets the condition in the form of a number, cell reference, text
string, expression or another Excel function. The criteria defines which cells shall be
counted and can be expressed as 10, "<=32", A6, "sweets".
• [criteria_range2, criteria2]… (optional) - these are additional ranges and their
associated criteria. You can specify up to 127 range/criteria pairs in your formulas.

Excel COUNTIFS - things to remember!


1. You can use the COUNTIFS function in Excel to count cells in a single range with a
single condition as well as in multiple ranges with multiple conditions. If the latter, only
those cells that meet all of the specified conditions are counted.
2. Each additional range must have the same number of rows and columns as the
first range (criteria_range1 argument).
3. Both contiguous and non-contiguous ranges are allowed.
4. If the criteria is a reference to an empty cell, the COUNTIFS function treats it as a
zero value (0).
5. You can use the wildcard characters in criteria - asterisk (*) and question mark (?).
How to use COUNTIFS and COUNTIF with multiple criteria in Excel

Formula 1. COUNTIFS formula with multiple criteria

Suppose you have a product list like shown in the screenshot below. You want to get a count of
items that are in stock (value in column B is greater than 0) but have not been sold yet (value is
column C is equal to 0).

The task can be accomplished by using this formula:

=COUNTIFS(B2:B7,">0", C2:C7,"=0")

And the count is 2 ("Cherries" and "Lemons"):

Formula 2. COUNTIFS formula with two criteria

When you want to count items with identical criteria, you still need to supply each criteria_range
/ criteria pair individually.

For example, here's the right formula to count items that have 0 both in column B and column C:

=COUNTIFS($B$2:$B$7,"=0", $C$2:$C$7,"=0")

This COUNTIFS formula returns 1 because only "Grapes" have "0" value in both columns.

Using a simpler formula with a single criteria_range like COUNTIFS(B2:C7,"=0") would yield a
different result - the total count of cells in the range B2:C7 containing a zero (which is 4 in this
example).
Using a simpler formula with a single criteria_range like COUNTIFS(B2:C7,"=0") would yield a
different result - the total count of cells in the range B2:C7 containing a zero (which is 4 in this
example).

Formula 1. Add up two or more COUNTIF or COUNITFS formulas

In the table below, supposing you want to count orders with the "Cancelled" and
"Pending" status. To have it doen, you can simply write 2 regular Countif formulas and
add up the results:

=COUNTIF($C$2:$C$11,"Cancelled") + COUNTIF($C$2:$C$11,"Pending")

In case each of the functions is supposed to evaluate more than one condition, use
COUNTIFS instead of COUNTIF. For example, to get the count of "Cancelled" and
"Pending" orders for "Apples" use this formula:

=COUNTIFS($A$2:$A$11, "Apples", $C$2:$C$11,"Cancelled") + COUNTIFS($A$2:$A$11, "Apples",


$C$2:$C$11,"Pending")
Formula 2. SUM COUNTIFS with an array constant

In situations when you have to evaluate a lot of criteria, the above approach is not the
best way to go because your formula would grow too big in size. To perform the same
calculations in a more compact formula, list all of your criteria in an array constant, and
supply that array to the criteria argument of the COUNTIFS function. To get the total
count, embed COUNTIFS inside the SUM function, like this:

SUM(COUNTIFS(range,{"criteria1","criteria2","criteria3",…}))

In our sample table, to count orders with the status "Cancelled" or "Pending" or "In
transit", the formula would go as follows:

=SUM(COUNTIFS($C$2:$C$11, {"cancelled", "pending", "in transit"}))


In a similar manner, you can count cells based on two or more criteria_range / criteria pairs. For
instance, to get the number of "Apples" orders that are "Cancelled" or "Pending" or "In transit",
use this formula:

=SUM(COUNTIFS($A$2:$A$11,"apples",$C$2:$C$11,{"cancelled","pending","in transit"}))

How to count numbers between 2 specified numbers

Formula 1. COUNTIFS to count cells between two numbers

To find out how many numbers between 5 and 10 (not including 5 and 10) are contained in cells
C2 through C10, use this formula:

=COUNTIFS(C2:C10,">5", C2:C10,"<10")

To include 5 and 10 in the count, use the "greater than or equal to" and "less than or equal to"
operators:

=COUNTIFS(B2:B10,">=5", B2:B10,"<=10")
How to use COUNTIFS with wildcard characters

In Excel COUNTIFS formulas, you can use the following wildcard characters:

• Question mark (?) - matches any single character, use it to count cells starting
and/or ending with certain characters.
• Asterisk (*) - matches any sequence of characters, you use it to count cells
containing a specified word or a character(s) as part of the cell's contents.

Tip. If you want to count cells with an actual question mark or asterisk, type a tilde (~)
before an asterisk or question mark.

COUNTIFS and COUNTIF with multiple criteria for dates

The COUNTIFS and COUNTIF formulas you use for dates are very much similar to the above
formulas for numbers.

Example 1. Count dates in a specific date range

To count the dates that fall in a certain date range, you can also use either a COUNTIFS
formula with two criteria or a combination of two COUNTIF functions.

For example, the following formulas count the number of dates in cells C2 through C10
that fall between 1-Jun-2014 and 7-Jun-2014, inclusive:

=COUNTIFS(C2:C9, ">=6/1/2014", C2:C9, "<=6/7/2014")

=COUNTIF(C2:C9, ">=6/1/2014") - COUNTIF(C2:C9, ">6/7/2014")


Example 2. Count dates with multiple conditions

In the same manner, you can use a COUNTIFS formula to count the number of
dates in different columns that meet 2 or more conditions. For instance, the below
formula will find out how many products were purchased after the 20th of May and
delivered after the 1st of June:

=COUNTIFS(C2:C9, ">5/1/2014", D2:D9, ">6/7/2014")

Example 3. Count dates with multiple conditions based on the current date

You can use Excel's TODAY() function in combination with COUNTIF to count dates based on
the current date.

For example, the following COUNTIF formula with two ranges and two criteria will tell you how
many products have already been purchased but not delivered yet.

=COUNTIFS(C2:C9, "<"&TODAY(), D2:D9, ">"&TODAY())


This formula allows for many possible variations. For instance, you can tweak it to count how
many products were purchased more than a week ago and are not delivered yet:

=COUNTIFS(C2:C9, "<="&TODAY()-7, D2:D9, ">"&TODAY())

SUMIF Function

The Excel SUMIF function returns the sum of cells that meet a single condition. Criteria can be
applied to dates, numbers, and text. The SUMIF function supports logical operators (>,<,<>,=)
and wildcards (*,?) for partial matching.

Syntax
=SUMIF(range, criteria, [sum_range])

Arguments

• range - Range to apply criteria to.


• criteria - Criteria to apply.
• sum_range - [optional] Range to sum. If omitted, cells in range are summed.

The SUMIF function takes three arguments. The first argument, range, is the range of cells to
apply criteria to. The second argument, criteria, is the criteria to apply, along with any logical
operators. The last argument, sum_range, is the range that should be summed. Note
that sum_range is optional. If sum_range is not provided, SUMIF will sum cells in the first
argument, range.
Worksheet example

In the worksheet shown, there are three SUMIF formulas. In the first formula (G5),
SUMIF returns total Sales where Name = "jim". In the second formula (G6), SUMIF
returns total Sales where State = "ca" (California). In the third formula (G7), SUMIF
returns the total of Sales > 100:

=SUMIF(B5:B15,"jim",D5:D15) // name = "jim"


=SUMIF(C5:C15,"ca",D5:D15) // state = "ca"
=SUMIF(D5:D15,">100") // sales > 100

Notice the equals sign (=) is not required when constructing "is equal to" criteria. Also
notice SUMIF is not case-sensitive; you can use "jim" or "Jim". Finally, notice that the
last formula does not include sum_range, so range is summed instead.
Criteria in another cell

A value from another cell can be included in criteria using concatenation. In the
example below, SUMIF will return the sum of all sales over the value in G4. Notice the
greater than operator (>), which is text, must be enclosed in quotes. The formula in G5
is:

=SUMIF(D5:D9,">"&G4) // sum if greater than G4

Not equal to

To express "not equal to" criteria, use the "<>" operator surrounded by double quotes
(""):
Blank cells

SUMIF can calculate sums based on cells that are blank or not blank. In the example
below, SUMIF is used to sum the amounts in column C depending on whether column
D contains "x" or is empty:

=SUMIF(D5:D9,"",C5:C9) // blank
=SUMIF(D5:D9,"<>",C5:C9) // not blank

You might also like