• 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
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
You are here: Home
Lost password?
sp_Search
Advanced Search
Advanced Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search

Please confirm you want to mark all posts read

Mark all topics read

sp_MobileMenu Actions
Actions
sp_LogInOut
Log In
sp_Search

Search Forums

sp_RankInfo
Ranks Information
Avatar

New/Updated Topics

General Excel Questions & Answers

  Sick leave periods in one cell

  removing pesky hidden xml sheets in a workbook

  Excel Is Running Slow

  Quartile reporting

  Data Validation with unique values

  Amortization

VBA & Macros

  error form doesnt send value to the main code

  VBA Update the body from a template email

  Send Email Code Error

Power Query

  How to add a new query for each cell of a column

  Source doesn't exist for Power Query folder

  Create list of working days

  Power Query - How to add multiple columns from parent to Nes…

Xtreme Pivot Tables

  Pivot Tables - Grand Totals AND Summary Percentages in the s…

Excel Expert

  new and deleted entries

Select Forum

  Rules and Guides

Forum Rules and Guides

  Public Forums - For Registered Users

General Excel Questions & Answers

Dashboards & Charts

VBA & Macros

Power Query

Power Pivot

  Course Members Only

Excel Dashboards

Power Query

Power Pivot

Xtreme Pivot Tables

Excel for Decision Making

Excel for Finance

Power BI

Excel

Word

Outlook

Excel Expert

Excel for Customer Service Professionals

Excel Analysis Toolpak

Excel Tables

Excel for Operations Management

Financial Modelling

Advanced Excel Formulas

Pivot Tables Quick Start

ForumsGeneral Excel Questions &…
sp_TopicIcon
COUNTA counting "blank" cells
Avatar
Cullen Pendleton
Posts: 7
Level 0
February 14, 2022 - 6:35 am

1

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
Avatar
Philip Treacy
Posts: 1514
Level 10
February 14, 2022 - 10:03 am

2

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
Avatar
Cullen Pendleton
Posts: 7
Level 0
February 14, 2022 - 11:22 pm

3

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
Posts: 617

Level 4
February 15, 2022 - 8:39 pm

4

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
Forum Timezone:
Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Lynnette Altomari, Karolis Kmitas, Roy Lutke, Jeff Krueger, Darrell Hodge
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)

Devices in use: Desktop (11), Phone (5)

Forum Stats:
Groups: 3
Forums: 24
Topics: 6214
Posts: 27243
Member Stats:
Guest Posters: 49
Members: 31894
Moderators: 3
Admins: 4
© Simple:Press

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • 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
 

Company

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

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.