Home » excel » How to check if an Excel Range is empty in C#

How to check if an Excel Range is empty in C#

Posted by: admin March 9, 2020 Leave a comment

Questions:

I want to check if a range (cells in row * column) is empty using C#. I can traverse through cells, but any bettter and faster way ? Any method to get range from selected/active cell and number of rows and column ?

How to&Answers:

I suppose that Excel.WorksheetFunction.CountA works not only with sheets but with any Range argument:

Use CountA to count the number of cells that contain data in a range
or array.

A value is any type of information, including error values and empty
text (“”). A value does not include empty cells.

If an argument is an array or reference, only values in that array or
reference are used. Empty cells and text values in the array or
reference are ignored.