Value used in formula is wrong data type

Hooch

New Member
Joined
Mar 30, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to compare a range against a single value to see if it exists and return a single Boolean T/F result. The formula is:
Excel Formula:
=IF(COUNTIF(RANGE,CRITERIA)>0, "TRUE", "FALSE")

The problem I'm having is the way I supply the RANGE to COUNTIF will be fine if I explicitly highlight a range on a worksheet, but if I supply the formula that generated that range directly to COUNTIF I get a data value error.

So the data looks like this in a table named 'Booked':

NameDate
A
02/05/2023​
A
27/01/2023​
A
26/01/2023​
A
05/06/2023​
A
12/06/2023​
A
24/03/2023​
A
13/06/2023​
D
27/02/2023​
P
30/01/2023​
P
05/06/2023​
P
25/09/2023​
Y
05/01/2023​
Y
27/03/2023​

I generate a range from this data matching based on 'name' i.e. =IF(Booked[Name]="A", Booked[Date], 0)

Which results in this range:


45048​
44953​
44952​
45082​
45089​
45009​
45090​
0​
0​
0​
0​
0​
0​

Now if I insert this data into D1 by putting the IF formula there, I can access this range in COUNTIF no problem i.e. =COUNTIF(D1#, 45048) gives me a result of 1

However, if I directly insert the IF statement that generated that range into my COUNTIF formula I get data type errors i.e. =COUNTIF(IF(Booked[Name]="A", Booked[Date], 0), 45048)
and instead of getting the result of 1, which is my intention I get this:

#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​
#VALUE!​

Does anyone know why a data type error would creep in here and if so how can I resolve this to get my intended output of "1" in D1 instead of a range of "#VALUE!" in D1:D13?

Sorry if I've formatted this post badly or left something out, please let me know, I'm new to excel and this forum so apologies.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Your formula produces an array, not a range, and COUNTIF will not work with arrays. You could use SUMPRODUCT instead:

Excel Formula:
=SUMPRODUCT((Booked[Name]="A")*(Booked[Date]=45048))
 
Upvote 0
The xxIFS function need a range, not an array.
Try
Excel Formula:
=COUNTIFS(Booked[Name],"A", Booked[Date], 45048)
 
Upvote 0
Solution
Thank you both so much and Fluff, the function you supplied in your solution is actually a much better way of doing what I'm trying to do, thanks.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

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