Columns delete when it appears


I have to automate an excel sheet and there’re few columns as below,

These columns needs to be delete when it appears. (It’s not appear always).
Kindly advise me on this.

Thank you.


You can use For Each for this

Use Read Range activity to read the excel file
After that place For Each activity and write as Datatable.Columns

Inside that place a IF condition and check the item.toString = on of the column Name then place Remove Data column activity

Hope this may help you


1 Like

Hi @Udesheyy

Please refer this post,

In this the solution has been provided, just change the column names to the one you don’t want.

Change col1,col4,col34 to the column names you have to delete.


Hi @Srini84

I tried this. And I’m getting error “Collection was modified; enumeration operation might not execute” like this.

Can you please help me to solve this.

Thank you.

Hi @Udesheyy
You’re getting this error because you can’t use for each to delete items from the collection. So. instead try this:

  1. Create a new datatable (new_dt)
  2. For each item( type: in old_dt.columns
  • If: item.columnname = “yourString”
    1. Then: Do nothing.
    2. Else: “Add Data Column”
      • Column: item
      • DataTable: new_dt
  1. Delete the old Excel file and then use a write range to write the new datatable on the same path.