VSTO c# Check if a cell is null

13,347

You were overthinking. Range.Value2 returns an object. So if you'd like to check for null reference, just do

if(Range.Value2 == null)
{
  //blah blah
}
else
{
  //blah blah
}

You probably should check out the online API documentation a bit more.

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.value2(v=office.14).aspx

http://msdn.microsoft.com/en-us/library/ms262200(v=office.14).aspx

Share:
13,347

Related videos on Youtube

David
Author by

David

Updated on September 14, 2022

Comments

  • David
    David over 1 year

    If one has a reference to a cell, how does one check if it is null?

    Pseudo Code:

    Excel.Range cell = (Excel.Range)MyRange.Cells[1, 1];
    if (cell.value2.IsNull) { Stuff }
    else { Other Stuff }
    

    Unfortunately, IsNull does not exist.

    • antonijn
      antonijn about 11 years
      cell.value2 == null? (I'm sorry if that's a useless remark, I don't know anything about excel interop)