Countif formula that references a range based on the value of a separate cell

maclachlan19

Board Regular
Joined
Jul 8, 2013
Messages
53
Sorry, I couldn't figure out a better way to present this.
I have a named Range in my spreadsheet.
I want to use a Countif formula. But I want the name of the range to be referenced from another cell.
I can't figure out how to write the formula.
In example 2 below, the cell E8 contains Range1
[TABLE="width: 795"]
<colgroup><col span="6"><col><col span="6"></colgroup><tbody>[TR]
[TD]


[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]Example 1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]Named Range[/TD]
[TD][/TD]
[TD="colspan: 2"]This formula works[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]302[/TD]
[TD="align: right"]303[/TD]
[TD][/TD]
[TD="align: right"]302[/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[TD="colspan: 4"]Formula is =COUNTIF(Range1,D5)[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]455[/TD]
[TD="align: right"]654[/TD]
[TD][/TD]
[TD="colspan: 2"]Example 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]480[/TD]
[TD="align: right"]409[/TD]
[TD][/TD]
[TD="colspan: 4"]I would like this formula to work[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]110[/TD]
[TD="align: right"]995[/TD]
[TD][/TD]
[TD="align: right"]302[/TD]
[TD]Range1[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="colspan: 3"]Formula is =COUNTIF(E8,D8)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]781[/TD]
[TD="align: right"]861[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 6"](I have referenced E8 in the formula but it doesn't work)[/TD]
[/TR]
[TR]
[TD="align: right"]235[/TD]
[TD="align: right"]582[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]185[/TD]
[TD="align: right"]991[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 795"]
<colgroup><col span="6"><col><col span="6"></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try it this way...

=COUNTIF(INDIRECT(E8),D8)

Cell E8 contains a text string so you need to use the INDIRECT formula to get Excel to convert it to a range reference.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top