Click here to Skip to main content
13,055,490 members (51,247 online)
Rate this:
Please Sign up or sign in to vote.
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 30-Nov-12 0:36am
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

Rate this: bad
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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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