Changing Column Names with if condition

I have read lot of thread here with the similar question but none has helped me.

I am trying to change the default column names( column1, column2 etc)

I have made an array(columnHeadersArray) of string with all possible default column names.

I read the data table in dtFInal.

Use for Each
column in dtFinal.Columns

dtFinal.Columns(column.ToString).ColumnName = “Week Ending”

I am getting error: Assign: Exception has been thrown by the target of an invocation.

I think that in your first if you should replace:

Where exactly does the error occure ?

@Hiba_B I made the change and still getting the same error at Assign.

In the assign, you should:
remove : colname = xxx
change into column.ColumnName = “Week Ending”
Not sure if this works, still waiting for my robot to be available

still get the same error.

Would you mind sharing your xaml file ?

Bold.xaml (12.5 KB)

Oh now I get it, you can’t have all of your columNames being named Week Ending

Either you rename only the first column (then you should add break activity after renaming), or you add an index.tostring after week ending (so that you have at the first column week ending 1, week ending 2, etc
Bold.xaml (13.1 KB)

I downloaded your workflow still getting the same error at Assign.

Sorry I have deleted the assign just after, here is the right one:Bold.xaml (13.6 KB)

@Hiba_B Assign error has been fixed.
But It doesnt change the column names in the data table.
I want to change only the columns that have default column names(column1, column2 etc) not all columns.

That’s strange, when i try it i have the new headers

did you keep in the write range the add headers checked ?

Cant you just write:

If column.columnName.contains(“Column”) then:

 assign: column.columnName = "string" (it has to be different for each next column, you cant 
 have 2 columns with the same name)



Thanks @Hiba_B Its working now.

1 Like

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