• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

COUNTA counting "blank" cells|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / COUNTA counting "blank" cells|General Excel Questions & Answers|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…COUNTA counting "blank" cells
sp_PrintTopic sp_TopicIcon
COUNTA counting "blank" cells
Avatar
Cullen Pendleton
Member
Members
Level 0
Forum Posts: 7
Member Since:
February 9, 2022
sp_UserOfflineSmall Offline
1
February 14, 2022 - 6:35 am
sp_Permalink sp_Print

Can anyone explain why COUNTA is counting apparently blank cells?

As shown in the attached sample workbook, I had case numbers in cells. Each cell frequently has multiple "case numbers" separated by semicolons, but sometimes the names also had extra spaces (usually after the text, sometimes within it). (see Original Data table in 1st tab). I had to fix this because I need to use a Case Matter Lookup table (also in 1st tab) to find "matter names" from "case numbers," but any extra spaces stop MATCH, VLOOKUP, etc. from working. Finally, I wanted to use COUNTA to count the number of matter names in each row.

My solution was to:

1) split the column by delimiter in Power Query (see Split_Case_Nos_at_Delimiter table in 2nd tab);

2) use TRIM to remove the extra spaces (see Split_Case_Nos_Trimmed table in 3rd tab). This also worked fine - VLOOKUP returned every matching matter name from the lookup table (subtable 1 on 3rd tab). I got rid of "N/A" values by nesting VLOOKUP within IFERROR to leave a "" (subtable 2 on 3rd tab).

But I got stuck on the 3rd step (counting the number of matter names in a row) because COUNTA kept counting every cell in the row, including the ones that looked totally blank to me. This was true whether the cell contains a formula returning a blank ("") value (as in subtable 2 of tab 3) or if I pasted value (as in subtable 3 of tab 3) to get rid of the formula. 

The only solutions I found were to either 1) select the "blank" cells and use DEL or Clear All or 2) use a unique text string in my IFERROR function that I could find/replace at one go. For the life of me, though, I can't understand WHY CountA is counting what appear to be blank cells. Does anyone have an explanation for this? Or a more elegant solution to the problem than subbing in a text string and then replacing it with nothing?

sp_AnswersTopicSeeAnswer See Answer
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1549
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
February 14, 2022 - 10:03 am
sp_Permalink sp_Print

Hi Cullen,

The result of your IFERROR when there is an error is "" , which is an empty string, and that isn't the same as a blank cell.

If you use COUNTA on a range that you've done nothing with, it'll count the empty cells as you'd expect.  If you then enter ="" into a cell in that same range, you'll see that COUNTA result changes.

To overcome your issue you could try 

=COUNTA(B37:J37)-COUNTBLANK(B37:J37)

or

=SUMPRODUCT(--(LEN(B37:J37)>0))

 

Regarding the use of COUNTBLANK in the first formula.  COUNTA says it will count the number of cells in a range that are not empty.  COUNTBLANK says that it will count the number of empty cells in a specified range.  So COUNTA and COUNTBLANK treat cells containing "" differently.  This is inconsistent behaviour, but once you learn this, you can work with it.  Really, the functions should be changed so that they both treat data in the same way.

Regards

Phil

sp_AnswersTopicAnswer
Answers Post
Avatar
Cullen Pendleton
Member
Members
Level 0
Forum Posts: 7
Member Since:
February 9, 2022
sp_UserOfflineSmall Offline
3
February 14, 2022 - 11:22 pm
sp_Permalink sp_Print

I figured it was something like that, Phil: I didn't appreciate the difference between an empty string and a blank cell. Thanks for the quick reply and the useful workaround!

Best,

Cullen

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 688
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
4
February 15, 2022 - 8:39 pm
sp_Permalink sp_Print

Just for info, you could also use something like:

=COUNTIF(B54:J54,"?*")

to only count cells with at least one character in them.

The following users say thank you to Velouria for this useful post:

Philip Treacy
sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Saliha Mohamed, David Eva
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
jaryszek: 183
Newest Members:
Ashley Hughes
Herbie Key
Trevor Pindling
Stevan Kanjo
Erin Sheldon
Nikita Bhatia
Sheilah Taylor
Clare Webber
David Jenssen
Dominic Brosnahan
Forum Stats:
Groups: 3
Forums: 24
Topics: 6526
Posts: 28576

 

Member Stats:
Guest Posters: 49
Members: 32810
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.