Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

excel

vsto

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 ?

like image 486
Cannon Avatar asked Jul 28 '11 05:07

Cannon


People also ask

How do you check if a row is empty in Excel using C#?

Range xlCell; do { rCnt++; str = "A" + rCnt; xlCell = (Excel. Range)xlWorksheet. get_Range(str, str); } while (xlCell. Value2 == null);

How do you check if a range of cells is empty in VBA?

To check if a cell is empty you can use VBA's ISEMPTY function. In this function, you need to use the range object to specify the cell that you want to check, and it returns true if that cell is empty, otherwise false. You can use a message box or use a cell to get the result.


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

like image 147
Boris Treukhov Avatar answered Oct 17 '22 12:10

Boris Treukhov