+ Reply to Thread
Results 1 to 7 of 7

Counta function counting blank cells

Hybrid View

  1. #1
    Registered User
    Join Date
    06-23-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    29

    Counta function counting blank cells

    I am using the counta function to count how many cells have data in them but blank cells are being counted. If I manually do "clear contents" on any of the cells then they are not counted. This is a large spreadsheet so I'm looking for a faster way to do a global "clear contents". Any suggestions?

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Counta function counting blank cells

    You could try http://dmcritchie.mvps.org/excel/join.htm#trimall
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    06-23-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Counta function counting blank cells

    Thanks Jeff but, ugghh, I'm having challenges following this. I am not super knowledgeable in macros so this one is bit above my head. Do you have any other solutions?

    Thanks!

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counta function counting blank cells

    Let's assume cell A1 is one of these blank cells that's being counted.

    Try to find out what's in the cell. In an empty cell enter this formula:

    =CODE(A1)

    What result do you get?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Registered User
    Join Date
    06-23-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Counta function counting blank cells

    Thanks - the macro worked!

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Counta function counting blank cells

    Without manually clearing those fields, a macro is required.

    Does this help?

    Paste code in a Normal module
    • Where to paste code
    • Highlight macro to copy >> Ctrl + C >> Open your workbook
    • Alt + F11 >> opens the Visual Basic Editor (VBE)
    • Ctrl + R >>opens the Project Explorer (if not already open on left side of screen)
    • Insert menu >> Module or Alt + I, M >> activates the Insert menu and inserts a Standard Module
    • Paste code >> Ctrl + V (right side of screen)
    • Alt + Q >> exits VBE and returns to Excel
    • Back in Excel >> Alt + F8 >> Macro Dialog Box >> Highlight macro >> Run

    Sub TrimALL()
       'David McRitchie 2000-07-03 mod 2000-08-16 2005-09-29 join.htm
       '-- http://www.mvps.org/dmcritchie/excel/join.htm#trimall 
       ' - Optionally reenable improperly terminated Change Event macros
          Application.DisplayAlerts = True
          Application.EnableEvents = True   'should be part of Change Event macro
       If Application.Calculation = xlCalculationManual Then
          MsgBox "Calculation was OFF will be turned ON upon completion"
       End If  
       Application.ScreenUpdating = False
       Application.Calculation = xlCalculationManual
       Dim cell As Range
       'Also Treat CHR 0160, as a space (CHR 032)
       Selection.Replace What:=Chr(160), Replacement:=Chr(32), _
         LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
       'Trim in Excel removes extra internal spaces, VBA does not
       On Error Resume Next   'in case no text cells in selection
       For Each cell In Intersect(Selection, _
          Selection.SpecialCells(xlConstants, xlTextValues))
         cell.Value = Application.Trim(cell.Value)
       Next cell
       On Error GoTo 0
       Application.Calculation = xlCalculationAutomatic
       Application.ScreenUpdating = True
    End Sub
    If this does not help, would you like to post the workbook and what you want to achieve?

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Counta function counting blank cells

    You are very welcome and thanks for the feedback.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1