If you want to just remove the columns not containing the headers, then you can read it as datatable and put the following in an assign statement to remove the columns you do not require,
If you use dt.columns obviously you will get error…that is the reason i gave the solution with counter and looping through columns using the column number
The issue in your code is that in for loop you cannot manipulate the datatable if that datatable is used in the in arguments…
Firstly, The Decision of preserving the Columns is decided based on the First Row. Hence we would need to identify which column indices there are non-empty values and preserve only them. For this we can use the below Expression to get the column Indices where the value is Empty for the first row data.
Here, DT is the input datatable and NonEmptyColumnIndices is a variable of type Integer Array.
Next, we can rename the column names for only these identified column indices using a For Each Activity like shown below :
In the assign activity , we have the below expression :