## 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 and H is in B9, cells B4, B5, B6, B7 and B8 are in between.

### Explaining formula in cell E16

#### Step 1 - Find value in cell D13 in cell range B2:B11

The MATCH function finds the relative position of a value in an array or cell range.

MATCH(D13, B2:B11, 0)

becomes

MATCH("B", {"A"; "B"; "V"; "X"; "C"; "T"; "N"; "H"; "A"; "C"}, 0)

and returns 2.

#### Step 2 - Find value in cell D14 in cell range B2:B11

MATCH(D14, B2:B11, 0)

becomes

MATCH("H", {"A"; "B"; "V"; "X"; "C"; "T"; "N"; "H"; "A"; "C"}, 0)

and returns 8.

#### Step 3 - Subtract positions

MATCH(D13, B2:B11, 0)-MATCH(D14, B2:B11, 0)

becomes

2-8 equals -6.

#### Step 4 - Remove sign

We don't know where the values are in the cell range so it may happen that we get a negative number from time to time, this example is such occasion. The ABS function removes the sign from a number.

ABS(MATCH(D13, B2:B11, 0)-MATCH(D14, B2:B11, 0))

becomes

ABS(-6)

and returns 6.

#### Step 5 - Subtract with 1

The calculation counts the last cell as well, we only need the cells in between.

ABS(MATCH(D13, B2:B11, 0)-MATCH(D14, B2:B11, 0))-1

becomes

6-1

and returns 5 in cell E16.

### Get Excel *.xlsx file

### Count values category

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 […]

This article explains how to count cells highlighted with Conditional Formatting (CF). The image above shows data in cell range […]

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

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 press with left mouse […]

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

The array formula in cell D3 calculates the number of unique distinct items based on the given date in column B. […]

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

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

This article demonstrates how to construct a formula that counts unique distinct values based on a condition. The image above […]

This article demonstrates formulas that count values in cell based on a delimiting character. The image above shows a formula […]

This post demonstrates a formula in cell D16 that counts overlapping dates across multiple date ranges. The date ranges are […]

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

This article demonstrates techniques on how to count cells based on the background color. I will also demonstrate user defined […]

In the previous post I explained how to count overlapping dates comparing a single date range against multiple date ranges. […]

This article demonstrates ways to count contiguous values in a column, in other words, values that repeat and are adjacent. […]

Question: My issue is that I get the date in this format: 7/23/2011 7:00:00 AM I am trying to count […]

NETWORKDAYS function returns the number of whole workdays between two dates, however the array formula I am going to demonstrate […]

Janib Soomro asks: In A column, there are dates in mmddyyy format and in B column, there are two variables […]

## Functions in this article

More than 1300 Excel formulas

## Excel formula categories

## Excel categories

### 5 Responses to “Count cells between two 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

How about this array formula?

=ROUND(SUM(MATCH(C12:C13,A1:A10,0)/2),0)

Thank you so much! I've been looking for this everywhere!!

Abby,

Thank you! Remember that the function only works if there are unique values (no duplicates) in the cell range (A1:A10).

hello! thank you so much! this is what i was looking for, but i need some more help if you can. My row data have duplicates, so its not working properly all the time, although every time i know a value that is between those two. Can this formula be adjusted to lookup a value between those two, so it will work?

thanks you again for your help!

Happy new year!

Hello! Thank you so much, do you know if it is possible to choose a range over four columns and two rows? Or is this not possible!