Error If: Object reference not set to an instance of an object

Hi everybody,

I have a problem in a condition inside an Excel Application Scope activity. I have to check if Cell A2 contains some text (two different texts) or if cell B2 is empty.

First I used 2 activities Read Cell To read the two cells in two string variables CellA2 and CellB2.

Then I used, still inside the Excel Application Scope, an If with the following condition:

CellA2.StartsWith(“text1”) OR CellA2.StartsWith(“text2”) OR CellB2 = “”

And I had the error in the subject, so I changed it to:

CellA2.StartsWith(“text1”) OR CellA2.StartsWith(“text2”) OR CellB2.IsNullOrEmpty

But still the same error. So I changed another time the condition to:

(Not CellA2.IsNullOrEmpty And (CellA2.StartsWith(“text1”) OR CellA2.StartsWith(“text2”))) OR CellB2.IsNullOrEmpty

And still the same error is popping up… What am I doing wrong?

Thanks a lot in advance for your help.

Best regards,
Franz

Try printing the cell values in separate writeline activity and see which cell value us throwing error

Thanks for the suggestion. Both cells are empty, so the write line is giving nothing…

In write give text as “cell a” and along with that print value…and see when you reach which cell it throws error?

Hello @franz.verga

Can you share the screenshot of the workflow which you have created?

Thanks

The problem is that you are using bitwise operators instead of logic operators.

Instead of “And” use “AndAlso”. Instead of “Or” use “OrElse”.

(Not CellA2.IsNullOrEmpty AndAlso (CellA2.StartsWith(“text1”) OrElse CellA2.StartsWith(“text2”))) OrElse CellB2.IsNullOrEmpty

Thanks a lot! That solved the issue!!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.