none
Excel NullReference Issue

    Question

  • Hello all!

    I am trying to automate file naming of some reporting and am running into issues with dates in excel files. The code below causes a NullReference Exception, and I am not sure why. Basically, when I use the Find method, if anything other than "null" is returned, I am assuming that this date exists within the spreadsheet and will determine a portion of the file name. Any ideas?

    tempRange = range.Find("Reporting Period End Date");
                            Excel.Range lastRow = currentSheet.UsedRange; 
                            nextRange = currentSheet.get_Range(tempRange, lastRow);

    if (nextRange.Find("december 31, 2009").Value != null || nextRange.Find("12/31/2009").Value != null)

    {

    quarter = "1";

    fiscalYear = "10";

    }

    Thanks for any help/advice!

    Sunday, July 21, 2013 1:37 AM

Answers

  • you can click F11 debug your codes in Visual Studio. According to the the exception, I assume the nextRange is null lead to the exception. And you also can get the use of find method from the link.

    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample

    Monday, July 22, 2013 3:19 AM

All replies

  • What is the line it happens in? What is the exact exception message? What is the stacktrace?


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Sunday, July 21, 2013 6:37 PM
  • you can click F11 debug your codes in Visual Studio. According to the the exception, I assume the nextRange is null lead to the exception. And you also can get the use of find method from the link.

    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample

    Monday, July 22, 2013 3:19 AM