Test for null cell in VB

I have seen some sample C# code posted using something similar to:

if (currentCell == NULL) …

But the same logic doesn’t work with VB because ‘=’ isn’t overloaded.

What is the workaround?

If it helps, i am trying to search for all instances of text within cells, and need to know when there are no more hits. My code is something like:

Dim foundCell As Cell
Dim prevCell As Cell = Nothing

Do
foundCell = cells.FindFormulaContains(searchTerm, prevCell)
If (foundCell = Nothing) Then 'ERROR HERE
Exit Do
End If
foundCell.Style.Number = 49
prevCell = foundCell
Loop While (Not foundCell.Value = Nothing)

Thanks for the help.

Hi,

Please change your code to:

Dim foundCell As Cell
Dim prevCell As Cell = Nothing

Do
foundCell = cells.FindFormulaContains(searchTerm, prevCell)
If foundCell Is Nothing Then

Exit Do

End If

foundCell.Style.Number = 49
prevCell = foundCell
Loop While (Not foundCell Is Nothing)

Thank you.