You are here:

# Excel/Counting the occurrences of a set of data

Question
Hi,

I have a datasheet with thousands of rows of data. I want to count the number of occurrences of a specific set of data sequenced in rows. For example:

In rows 2000 to 2005 I have the following data

Row      Data
2000      Ssa
2001      Ddf
2002      Egt
2003      Wfd
2004      Xhy
2005      Zlk

I need to know how many times this exact sequence happened in my data, keeping in mind similar data may have occurred in other cells but not in the same sequence which in this case shouldn't be counted.

Thanks
Mo

Mo

Assume you data is in cells (A2:A1000) then

=SUMPRODUCT(--(\$A\$2:\$A\$995="Ssa"),--(\$A\$3:\$A\$996="Ddf"),--(\$A\$4:\$A\$997="Egt"),--(\$A\$5:\$A\$998="Wfd"),--(\$A\$6:\$A\$999="Xhy"),--(\$A\$7:\$A\$1000="Zlk"))

so since you are starting in A2, my first check is to

A2:A995   which is 994 rows.  each of the ranges in the subsequent sections must be 994 rows and must increment by 1.  so the formula first checks

=SUMPRODUCT(--(\$A\$2="Ssa"),--(\$A\$3="Ddf"),--(\$A\$4="Egt"),--(\$A\$5="Wfd"),--(\$A\$6="Xhy"),--(\$A\$7="Zlk"))

if all of those are true, it will result in a 1 and if not, then a zero.

it progresses through the 994 rows and makes this count.  The result will be the total number of occurances where a sequence of 6 rows hold the values you specify in the sequence you specify.

Tested and worked for me.

You will just need to adjust the ranges to reflect the range you want to check.

--
Regards,
Tom Ogilvy

This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

#### Tom Ogilvy

##### Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

##### Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.