How to Use CountA in Excel VBA

Written by david somerset
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Use CountA in Excel VBA
CountA detects the number of non-empty spreadsheet cells. (number background image by kuhar from

Visual Basic for Applications (VBA) is a powerful, user-friendly programming language that you can use to create macros within the Microsoft Excel spreadsheet program. Advanced users can also use it to create full applications that run within Microsoft Excel. When you write VBA macros or programs, you can use the standard Excel statistical functions to perform tasks. One task that the application can easily perform is to count the number of non-empty cells in a certain range of cells. The command to perform this task is called CountA.

Skill level:


  1. 1

    Click on "Start" and then "All Programs" and point to "Microsoft Office." Open "Microsoft Excel" to start the program.

  2. 2

    Press "Alt" and "F11" at the same time to open the "Visual Basic Editor." Select "Insert" and click on "Module."

  3. 3

    Include the line "COUNTA(argument1)" in your VBA code where "argument1" is the range in which you want to count the number of non-blank cells. For instance, enter "a1:a5" to count the number of non-empty cells in the range from "a1" to "a5" of your spreadsheet.

  4. 4

    Press "Alt" and "Q" to exit the "Visual Basic Editor" view.

  5. 5

    Press "Alt" and "F8" to bring up the list of created macros. Select the macro you created using the "CountA" function and click "Run" to execute the code that includes "CountA."

Tips and warnings

  • You can include more than one argument in the CountA function. Separate multiple arguments by commas.
  • You can enter a single cell rather than a range of cells for an argument to CountA.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.