Click here to Skip to main content
11,575,109 members (56,753 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 30-Nov-12 0:36am
Frans Jan2.4K
Comments
Mendor81 at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I personally would try to use

if(targetSheet.Cells[22, 27].equals("1"))
{
//do things
}
  Permalink  

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web03 | 2.8.150624.2 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100