none
How to detect blank/empty cells in Excel VSTO? RRS feed

  • Question

  • Hi,

    What is the best way to detect a cell is empty in Excel VSTO?

    I tried like using

                IfTrim(Cells(row_id, column_id).Text).Length = 0 Then

                    code...

                End If

    But the condition statement is TRUE even for some blank cells.

    What makes matters worse is that the worksheet function ISBLANK() is not usable in VSTO.

    Could anyone give a solution?


    Bob


    • Edited by Bob Sun Monday, March 5, 2012 10:37 PM
    Monday, March 5, 2012 10:36 PM

Answers

  • You should look at the Worksheet.Range property.  Here's an example from the Excel Developer Reference.

    numBlanks = 0 
    For Each c In Range("TestRange") 
     If c.Value = "" Then 
     numBlanks = numBlanks + 1 
     End If 
    Next c 
    MsgBox "There are " & numBlanks & " empty cells in this range"


    Kind Regards, Rich ... http://greatcirclelearning.com

    • Marked as answer by Bob Sun Tuesday, March 6, 2012 10:31 AM
    Monday, March 5, 2012 11:34 PM

All replies

  • You should look at the Worksheet.Range property.  Here's an example from the Excel Developer Reference.

    numBlanks = 0 
    For Each c In Range("TestRange") 
     If c.Value = "" Then 
     numBlanks = numBlanks + 1 
     End If 
    Next c 
    MsgBox "There are " & numBlanks & " empty cells in this range"


    Kind Regards, Rich ... http://greatcirclelearning.com

    • Marked as answer by Bob Sun Tuesday, March 6, 2012 10:31 AM
    Monday, March 5, 2012 11:34 PM
  • Rich,

    It worked. Thanks.

    Bob

    Tuesday, March 6, 2012 10:32 AM