Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Countifs function in Excel

0

Im using a simple COUNTIFS function to count rows of data based on content in another cell. The problem is that when there is no data to count it is still giving me a value of 1. When there is no data it should read 0, but instead it is reading 1.

The formula is =IF(ISBLANK(C2),COUNTIFS(A:A,A2,C:C,">0"),"")

Anyone have any idea why COUNTIFS would give a value when it shouldn't?

I have inserted an abreviated sample file but am unable to duplicate the problem

Answer
Discuss

Discussion

G1zmos

I got a notification just that your question had been updated but I can't see how.

Didn't my Answer solve your problem?If so, please mark it as Selected. If not, please edit your question to attach a file and explain more fully what you're trying to do. 
John_Ru (rep: 6142) Jan 25, '23 at 12:59 pm
The first row in my Table is the name and number of the document I am listing, subsequent rows contain the tests that being conducted within the document and these tests are numbered in Column K, with the document number repeating in Column A. My formula was written to count only the rows with corrosponding matches of the documnet number in Column A but only if the value in Column K is ">0", I also tried to use ">=1"
Only on row 367 does this anomaly happen and only in my one worksheet. The reason I have not attached an example file is because when I take out a sample I am am not able to duplicate the problem again..
Your suggestion #1 gave me 3 as an answer, #2 resulted in 5, and number 3 also gives me 3. The correct count is 2, again only on row 367...
G1zmos (rep: 2) Jan 25, '23 at 2:19 pm
You're not making this easy! Not sure if I can replicate the problem (when I get home later). Could you edit your question to attach the file but with the other sheets and data (except for "faulty" row 367 and one other "working" row) is overwritten with test data or deleted? 
John_Ru (rep: 6142) Jan 25, '23 at 2:38 pm
Thanks for attaching the sample file. I took a quick look (on my mobile phone) and see what you're doing.

Your formula makes sense too and will count all tests matching the value in column A. If you have several hundred rows, are you sure that tests like A367 aren't repeated anywhere else? I'd apply Autofilter, deselect all then check the filter value for A367. If that doesn't show duplicates, check the values in K are numeric and there's nothing in C (not a space or non-printable character). 
John_Ru (rep: 6142) Jan 26, '23 at 12:54 pm
John
I went back as suggested and applied Occam's Razor (also known as the 'law of parsimony') suggestion to the data . Sure enough in a previous work period (a few years back) there was a document that had the same number, row 367 has been renumbered as Issue B & problem solved. I will keep that tidbit of advice in my tool chest for future dificulties... Thank You!
G1zmos (rep: 2) Jan 26, '23 at 3:18 pm
Hi G1zmos. Glad that helped. Next time, please make your question as complete as possible and attach a representative file- that way I (or someone else) might give an Answer which solves your issue and you decide can be marked as Selected- that increases the answerer's reputation (and is our only tangible reward for helping users).
John_Ru (rep: 6142) Jan 26, '23 at 4:06 pm
Add to Discussion

Answers

0
Selected Answer

Hi G1zmos and welcome to the Forum.

Without a file, it's difficult to see what you're trying to do. Please note that you could edit your question and use the Add Files... button to upload a representative Excel file (without any personal data) to show your existing macro and data. 

However your formula (which should end in a right bracket):

=IF(ISBLANK(K367),COUNTIFS($A:$A,A367,$K:$K,">0")

means "if K367 is blank, count the number of rows where both the value in column A equals that in A367 AND the value in column K equals that in K367; otherwise give the value is FALSE". If you put a number in K367, that meets the second criteria of the COUNTIFS formula and  A367 (whatever it is) will match itself so you will have 1 matching row as the result of the COUNTIFS portion.

I suspect that's not what you want so have given you 3 possibilitles in the attached file.

In cell D1, Formula 1 is this:

=COUNTIFS($A:$A,">0",$K:$K,">0")

This simply counts the rows where cells in both A and K are greater than 0. My guess is that's what you want.

If however you want to display or not display a count (based on a cell like K367) then cell D10  (shaded yellow) controls Formula 2 in pale green cell D12:

=IF(ISBLANK(D10),COUNTIF($A:$A,">0"),"-")

so it counts cells above 0 in column A if D10 is blank (otherwise shows "-").

In a similar way, Formula 3 in pale orange cell D14 is:

=IF(ISBLANK(D10),COUNTIFS($A:$A,">0",$K:$K,">3"),"-")

where if D10 is blank, it counts rows where A is greater than 0 but K is greater than 3.

Hope this helps. If so, please remember to mark this Answer as Selected.

Discuss

Discussion

Thanks for selecting my Answer 
John_Ru (rep: 6142) Feb 2, '23 at 4:42 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login