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 ?
Range xlCell; do { rCnt++; str = "A" + rCnt; xlCell = (Excel. Range)xlWorksheet. get_Range(str, str); } while (xlCell. Value2 == null);
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With