How to Use CountA in Excel VBA

Updated April 17, 2017

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.

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

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

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.

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

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."


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.

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

David Somerset has been a writer intermittently for 11 years. He attended New Mexico Tech and earned a Bachelor of Science in technical communication in 2007. From being published in the "Bucksworth Community News" to writing how-to articles for eHow, his experience is quite diverse.