## Count contiguous values

In column A, I have a long random list of two variables, "N/A" and the value 1. In column B I want to identify the number of contiguous occurrences of the value 1 before the next appearance of "N/A". I wonder if you could point me to the best way of achieving this please? Example below shows what I am after.Much appreciation for your excellent website,

DavidCol A Col B

N/A

N/A

1

1

1

1

1 5

N/A

1

1

1

1 4

N/A

N/A

1

1 2

N/A

N/A

N/A

1 1

Thanks, David.

The following formula looks for contiguous values, not only 1 and N/A.

**Array formula in cell B3:**

Read Rick Rothsteins's comment.

**How to enter an array formula**

- Select cell B3
- Paste above formula to formula bar
- Press and hold CTRL + SHIFT simultaneously
- Press Enter once
- Release all keys

Copy cell B3 and paste to cells below as far as needed.

If you want to learn more about array formulas join my Advanced excel course.

### Download excel *.xlsx file

identify-the-number-of-contiguous-occurrences-of-a-value-david.xlsx

Count unique distinct values that meet multiple criteria

This post demonstrates how to build an array formula that counts unique distinct values based on criteria. What's on this [โฆ]

This article describes how to count unique distinct values. What are unique distinct values? They are all values but duplicates are [โฆ]

Count cells between specified values

This article demonstrates formulas that calculate the number of cells between two values, the first scenario involves two search values [โฆ]

Count unique distinct values in two columns

Formula in C12: =SUM(1/COUNTIF($B$3:$B$8, $B$3:$B$8))+SUM(IF(COUNTIF($B$3:$B$8, $D$3:$D$8)=0, 1/COUNTIF($D$3:$D$8, $D$3:$D$8), 0)) How to create an array formula Double click on cell C12 [โฆ]

Count unique distinct values in a filtered Excel defined Table

This article demonstrates a formula that counts unique distinct values filtered from an Excel defined Table. Debra Dalgleish described in [โฆ]

Count unique distinct values within same week, month or year

The array formula in cell E3 counts unique distinct items for all dates within the same week. Example, week 2 [โฆ]

Count overlapping days in multiple date ranges

The MEDIAN function lets you count overlapping dates between two date ranges. If you have more than two date ranges [โฆ]

Count cells between two values

The formula in cell E16 counts the number of cells between value B and H, Value B is in cell B3 [โฆ]

Count overlapping days in multiple date ranges, part 2

In the previous post I explained how to count overlapping dates between a single date range and multiple date ranges. In [โฆ]

Count unique distinct records with a date and column criteria

davidlim asks: re: Count records between two dates and a criterion based on the example, i was looking for 1 [โฆ]

### 4 Responses to โCount contiguous valuesโ

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

First off, you show your formula starting in cell B3... you need to adjust it so that it starts in cell B2, otherwise you will not show a 1 in cell B2 if cell A2 differs from cell A3.

Second, here is a much simpler, still array-entered, formula, placed in cell B2 and copied down, that appears to produce the same output as your formula...

=IF(A3<>A4,ROW()-MAX(IF(A$1:A2<>A3,ROW(A$1:A2))),"")

Sorry, I posted the wrong formula, plus it looks like the comment processor ate my less than greater than symbol. Here is the correct array-entered formula, rearrange to eliminate the display problem...

=IF(A2=A3,"",ROW()-MAX(IF(A$1:A1<>A2,ROW(A$1:A1))))

D@MN! I missed that the comment processor ate a second less than, greater than symbols in my formula. Here now is the correct [b]array-entered[/b] formula (rearranged so that there are no less than, greater than symbols at all)..

=IF(A2=A3,"",ROW()-MAX(IF(A$1:A1=A2,,ROW(A$1:A1))))

Rick Rothstein (MVP - Excel),

Your formulas work fine, thanks. So much better and smaller than mine.

I am sorry for wordpress eating your less/greater than signs, I try to edit your comments as soon as I can.