Index was out of range. Append to XL

Hey all,

So i have a workflow that works. It gets data from an API (in text form) and manipulates the data then appends it to a specific tab on my Excel file (different tabs for different store location in company). repeats for different store locations and appends to each stores “tab” in XL…been working fine for 6 months+

We decided to add a new tab which contains Pivot table data and other XL functions and stuff. The Automation does not interact with this tab, but it throws an error when trying to post the first datatable to the first store tab. I moved this new tab to the end, but still get the same error.

I removed the new tab and the Workflow works like it used to. So the issue is the new tab.

But the error is weird:
Source: Append Range
Message: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Exception Type: System.ArgumentOutOfRangeException

to debug, I used a write line before the append range to make sure my dtb had data in it: (dtbname.rows.count.tostring) and it returned 137. so i know my dtb is not blank.

anyone know a reason why a tab on XL is screwing with append range, even though the Automation is not using/interacting with that tab?

Thanks

Hi @MikeBlades

I understand that you are adding the data to each tab programmatically, I think when you are moving from one tab to other the index of each sheet might be disturbed when you added new tab/sheet.

check if the tab names/index in the excel are in sync with the UiPath code.

Hope this is helpful

@MikeBlades It looks like you are trying to access the data or perform actions with the rows that were not present in the data table

Index must be non-negative means the lowest possible index range that can exists is 0 .You are saying that the data table has 137 rows that means you can access from 0-136, not 137 th row

Instead of appending the data try to write the data in a separate excel excel sheet. If it was not showing the current error, then there is something wrong with the current logic

Don’t know what the issue was, but i fixed it but putting the Write Range inside an Excel app scope.

Still keen to know why a separate tab (with pivot tables) affects other tabs when using a Write Range…it’s weird

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