How to deal with the foreach error with an empty row in datatable

I’m doing the vlookup of excel and use the foreach and always show a error “Objective reference not set to an instance of an object.” I check my codding and find there is a empty row in my datatable used to do the foreach after removing duplicates. Because of the empty row, when the loop goes to this row, it will show error. To solve this problem. I think there are several ways. (may not be correct)

  1. Remove the empty row in datatable
  2. Choose the exact cells instead of choosing the collomn when remove duplicates which cause the empty row in my datatable
  3. During the Foreach, when no value send to the variable. Go for the next row and continue the loop.
    Can anybody help me to check my judgment to this error and explain any of the solutions in detail? Thank you very much!


Can you attach the workflow. It might be faster just to give you an example wf.

A simple question is that how to remove duplicates in database without a empty row

Here is an example with removing identical rows. If you need to remove rows based on a certain column value it might be a little more difficult.

RemoveDuplciateRows.xaml (8.3 KB)

1 Like

Not more difficult , simplest way may be to use "Get row item " in datatable for-each with a property of ‘ColumnName’ and by using that return value and if condition on true use Remove Data Row activity.


It works! Thank you very much

Hello, I would be very interested to know how to solve “3. During the Foreach, when no value send to the variable. Go for the next row and continue the loop.”
Does anyone have the solution ?


Would you be able to go into further detail on how to accomplish this? Specifically, how to use a return value in a “get row item” as well as what expressions to use in the if conditions. Also, how would I use the “remove data row” to remove the duplicate value for the cell?

Hi Akshay, when I am using for each row in a data table, if row contains nothing or “” it is throwing error as null reference error, how to avoid this .

sorry bro I got it

Good day,

How were you able to solve this? Thank you in advance.