Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm getting this error:
Object reference not set to an instance of an object.
on this line:
if (isDone.get_Value(oMissing).ToString() == "1")
in the following code:
using xlNS = Microsoft.Office.Interop.Excel;

xlNS.Range isDone;
isDone = targetSheet.get_Range("AA23", "AA23");

if (isDone.get_Value(oMissing).ToString() == "1")
{
        //Do things
}

My original value of isDone was:
isDone = targetSheet.get_Range("AA22", "AA22");
but I found out that I was overwriting an existing value on AA22, so I turned it into AA23. this little change resulted in the error. I have no idea why and how to fix it...
Posted
Comments
Mendor81 30-Nov-12 6:44am    
So basicly the AA23 cell is empty?
and it worked with the AA22?

And what and where is oMissing declared/instantiated ?
Frans Jan 30-Nov-12 7:03am    
AA23 is not empty. It has a IF statement, with 0 when true and 1 when false. Default is true, so it's default value is zero, not empty.
object oMissing = Type.Missing;

1 solution

I personally would try to use

C#
if(targetSheet.Cells[22, 27].equals("1"))
{
//do things
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900