Write datatable but creates extra rows

Hi there,

I create a counter = 11, this is to write range from cell I11 onwardes where the range is I + counter in for each row activity. And at the bottom after writing the row i add counter = counter + 1. It writes correctly but however it adds in additional rows. I am not sure where is the issue lying?

@mark_rajkumar1 Have you placed any if activity in foreach row data table or any condition?

Or please share a screenshot of the workflow for better understanding.

Regards,
Ajay Mishra

Yes i have input if string is null or empty

@mark_rajkumar1 If you are not incrementing your counter within the if then it would increment irrespective of your condition. So you would get additional rows.

My increment is within the if only

Not sure why it increment extra 2 or 3 rows

could you share screenshot of your workflow

Due to confidentiality i am unable to share

@mark_rajkumar1 Any dummy data if you can prepare? So that we will have better understanding!

Regards,
Ajay Mishra

@mark_rajkumar1,

Check if there is any additional blank row at your datatable before Write Range. If exist remove them using Filter DataTable activity.

Thanks,
Ashok :slight_smile:

I realise there is a typo error, i use write cell not write range as described as above.

@mark_rajkumar1,

In case of Write Cell, check if the value you are going to write is not Null or empty.

This is not a correct way to control where the data is written. You set the Starting Cell property in the Write Range activity to tell it where to start.

If you’re doing this because there is already data in the first 10 rows, then just use Append Range. It’ll automatically start writing the data after the last existing row.

@ashokkarale yes there is a if condition to check is null or empty

@postwick i am writing it in such manner as the column are seperated in the excel

Without more detail I’m not sure exactly what you mean, but if you need to leave some columns empty you just add empty columns to your datatable before the Write/Append Range.

@postwick i need to reshuffle some columns as well. So i use write range activity?

If you need to rearrange columns, use this expression…

Assign myDT = myDT.DefaultView.ToTable(False,“column 1”,“column 2”,“column 3”)

Of course replace those column names with the names of the columns in your datatable, in the order you want them.

The point is you have to get the data in the datatable formatted and arranged the way you want it, then use Append Range to write it to starting at the first available row in the Excel file.

I suggest doing the free training on the UiPath Academy web site, it’ll teach you how to do these basic things.