Sie sind auf Seite 1von 16

# Eight ways to exploit COUNTIF() and sumif()

Posted on November 12th, 2008 in Learn Excel - 78 comments

If for every countif() I write excel paid me a dollar, I would be a millionaire by now. It is such a
versatile and fun formula to work with that I have decided to write about it as third post in

1.

## Using COUNTIF() to replace pivot

tables: We all know that you can use countif() to replace pivot tables for simple data
summarization. For eg. if you have customer data in a table and you would like to know how many
customers you have in each city you can use countif() to find that.
countif("master-data-range","city name")
More on this method of using countif and 4 other ways of using excel if () formulas

2.

Counting Valid Phone Numbers in a Range: Using operators < and > in countif() you can
findout valid phone numbers in range like this: countif("data-range",">"&1000000000)

3.

Finding number of customers in a city based on their phone number: This trick may
not work perfectly. We can use countif("data-range","22*") to findout total customers in
Mumbai (since all Mumbai phone numbers begin with 22)
Note: This method works as long as phone numbers have identifiable calling codes and stored as
text. To covert a number to text you can use text() or append an empty space to the number.

4.

Pattern matching: Often when you extract data from other sources and paste it in excel it is
difficult to process it when the formats are not consistent. For eg. when you copy address data of a
bunch of customers and need to know how many customers are in New York you can use countif
like this: countif("data range", "*new york*"), the operator * tells excel to match any cell with
new york in it, not necessarily at the beginning or end of the cell.

5.

Counting positive numbers in a range: Again we use the > operator to count the positive
numbers in a range like this: countif("data-range",">0").

A very good use of this trick is when you need to calculate average of a bunch of numbers but need
to exclude zeros: sum("data-range")/countif("data-range","<>0")
6.

## As a replacement to FIND(): Excel FIND() is powerful formula to find if a particular text

occurred in another text. But one problem with find is it returns #value! error if the value you are
looking for is not in the input cell. What if all you need to know was whether your cells had a
particular value or not?You are right, you can use COUNTIF() for that too, like: countif("cellyou-want-to-look","*hilton*") will return 1 or 0.

7.

For sorting text: Read more on this at sorting text using excel formulas

8.

## Findout the number of errors in a sheet: The beauty

of countif() is that you can even count error cells. For eg. you can use it
like:=COUNTIF(1:33,"#VALUE!") to findout how many #VALUE! errors were there in the rows from
1 to 33. This can be useful if you are building a complex model and need to keep track of errors.

## Most of the tricks should work with SUMIF() as well.

If you like this, read the other posts in the spreadcheats series. It is a 30 post series (3 posted so
far) that aspires to make YOU very good in using excel to solve day to day problems.

## Do you want to be awesome in Excel?

Here is a smart way to become awesome in Excel. Just signup for my Excel newsletter. Every
week you will receive an Excel tip, tutorial, template or example delivered to your inbox. What more,
as a joining bonus, I am giving away a 25 page eBook containing 95 Excel tips & tricks. Please signup below:
Name:
Email:

## How to Create a Retail PointofSale

System with Excel
Community Q&A

Do you need a simple POS (point of sale) system for your small retail shop? With this
method, you can manage the following facilities without special software or expensive
equipment:

## Issue a sales bill using barcode

Manage purchases

Control inventory

## Day end and month end stock balance

Daily sales

Daily purchases

Steps

1. 1
Learn Microsoft Excel. Learn about Excel macros.
o

Create Excel workbook with 6 worksheets for followings steps like this:

Bills

Pur

Purchase

Sales

Stock balance

Setup

2
o

Category Code : Create specific codes for your each item. This must be a unique
ID number for each items. Use this to create the barcodes.

According to this, take all the inventory items & create a code and update the
sheet with opening stock, pur, price, and sales price. You have to give the correct purchase price
and sales prices because when you issue a bill, price will be selected from this sheet. The
opening balance will be linked with the stock balance sheet. If you dont have a barcode printer,
just print the receipt to A4 Sheet and paste it to your sales items.

## Copy this formula to each row and copy paste to down:

Code: =IF(setup!\$B\$3:\$B\$323<>"",setup!\$B\$3:\$B\$323,"")

Description: =IF(setup!\$C\$3:\$C\$323<>"",setup!\$C\$3:\$C\$323,"")

## Opening Balance: =SUM(IF(B3=setup!\$B\$3:\$B\$1021,setup!\$D\$3:\$D\$1021))

Purchase: =SUM(IF(B3=purchase!\$B\$2:\$B\$2005,purchase!\$D\$2:\$D\$2005))

Sales: =SUM(IF(B3=sales!\$H\$2:\$H\$2551,sales!\$J\$2:\$J\$2551))

Stock: =+D3+E3-F3

3
Create a bill sheet:
o

Create a sheet according to this format and give the below formula to each row
and create macros with below codes.

Line: =IF(C5="","",B4+1)

Code: Create a list box link with setup page item code and name. when you

connect a bar code reader with bar code sticker details will auto pick.
o

Description: =I4

Qty : this column you have to enter manually according to customer purchase qty.

Price: =IF(E4="","",VLOOKUP(C4,al,5,0)*E4)

## macro for Save bill

Create a button called Save bill and copy this code: You can download
this file form file

Sub Dayendsales()'

'Dayendsales Macro

Sheets("Tsales").Select

Columns("G:G").Select

## Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Range("E2:E255").Select

Selection.copy

Range("G2").Select

## Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,

SkipBlanks _
=False, Transpose:=False

Sheets("sales").Select

Range("B3:D1572").Select

Application.CutCopyMode = False

Selection.ClearContents

Range("D3").Select

End Sub

Sub DayendPurchases()'

## ' DayendPurchases Macro'

Sheets("Tpurchase").Select

Columns("F:F").Select

## Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Range("D2:D643").Select

Selection.copy

Range("F2").Select

## Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,

SkipBlanks _
=False, Transpose:=False

Application.CutCopyMode = False

Sheets("purchase").Select

Range("C3:D625").Select

Selection.ClearContents

Range("E3").Select

End Sub

Sub SaveBill()'

End Sub

Sub DayEnd()'

## ' DayEnd Macro

End Sub

4
Create a Pur sheet: according to this format

Now create the Purchase and sales data save page with this format:

## Mini Excel Tutorial: Using Advanced

Excel
Written by Dann AlbrightMarch 19, 2015

## Excel formulas can do a lot of really great things, from helping

you get your finances together to helping manage your entire life. You
might think of counting and adding formulas as relatively mundane
compared to more advanced formulas that are out there, but having
a good handle on these functions can help you save a lot of time
when you need to collect information about the data in your

COUNT
The COUNT function counts the number of cells in a range that have
numbers in them. If you use a formula to run a lot of calculations,
you may find yourself wondering how many times it workedCOUNT
can help here. If a formula returns an error (like #DIV/0!) for some
entries, you can easily find out how many times that happened.
COUNT only counts a cell if it contains a number, a date, a logical
value, or a text representation of a number. If you want to include

cells that have text, error values, and empty text, use the COUNTA
function. To do the opposite, use COUNTBLANK.

## Heres the syntax for the COUNT function:

=COUNT([range1], [range2]...)

The [range] argument defines the range of cells that you want to do
with www.generatedata.com), we have columns for first name, last
name, city, state, and SAT score. Some of the SAT scores are
missing, and were going to find out how many. We know that there
are 100 people in the spreadsheet, so well use COUNT on the SAT
score column with the following syntax:
=COUNT(E:E)

## Heres the result:

As you can see, 85 students have values in the SAT score column, so
were missing scores from 15 students.

COUNTIF
This function is very similar to COUNT, but lets you set the criteria
for which cells get counted. Heres the syntax:
=COUNTIF([range], [value])

## As with COUNT, the [range] argument is used to choose the range of

cells in which you want to count. The [value] argument is where you
put in your criterion. For example, if you want a count of all the
students in the spreadsheet that live in Minnesota, you would use
the following syntax:
=COUNTIF(C:C, "Minnesota")

You could use this method for counting the number of students who
scored above a certain number, for example, by using >1500 as
your argument. You can also use a cell as a counting reference. Well
do that here to see how many students live in Texas. Well use the
following syntax:
=COUNTIF(D:D, D2)

The cell D2 contains Texas, and we can use the cell reference
instead of typing out the name of the state.

COUNTIFS
Whereas COUNTIF lets you count based on a single criterion,
COUNTIFS lets you use as many criteria as youd like. You can also
use it to count based on multiple criteria in multiple ranges. Heres
the syntax:
=COUNITFS([criteria_range1], [criteria1], [criteria_range2],
[criteria2])
Well use this to see how many students from Hawaii scored over
1500 on their SAT. Heres the syntax well use:
=COUNTIFS(D:D, Hawaii, E:E, >1500)
When we run that, this is what we get:

SUMIF
You probably know how to use SUM to add up a series of numbers
(like Brad used in creating his Excel dashboard), but what if you only
want to add up a portion of those numbers? SUMIF lets you choose
which cells are added by specifying a criterion. Heres the syntax:
=SUMIF([range], [criteria], [sum_range])

## The [range] argument is self-explanatory, and the [criterion]

argument can be a specific value, or a logical operator. For example,
you could add all of the cells in a list that are greater than 500. The
[sum_range] argument is a very useful one; if you input a range in
this position, SUMIF will add the cells in a different range that are
specified by the first range.

## Its easier to use a visual explanation. In our example spreadsheet

below, we have a list of names and a list of donations. To add all of
the donations collected by David, well use this syntax:
=SUMIF(A:A, "David", B:B)

## Wherever Excel found David in column A, it added the value in

column B.

SUMIFS
If you want to use multiple criteria to select which cells to add you
can use SUMIFS. The syntax is a bit different than SUMIF:
=SUMIFS([sum_range], [criteria_range1], [criteria1],
[criteria_range2], [criteria2])

## As you can see, the [sum_range] argument comes first, instead of

third, as it does in SUMIF.
state in which the donations were gathered. Using SUMIFS, we can
see how much John collected in Michigan with the following syntax:
=SUMIFS(B:B, A:A, John, C:C, Michigan)
Lets see what it turns up.