Click here to Skip to main content
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 1:36am
Frans Jan2.2K
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
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
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