How to change the name of a column in excel, if the columns already exists?

Hi everyone!

I have multiple excel files and I’m having an issue processing them. Some of the files have columns with the same name what generates an error.
There is a way to run through all excel files and rename the repeated column?
For example, I have to columns name “description” and I want to rename the second appearance to “description_2”.

Thanks in advance!

Hi,

If the column is always at the same position, you can use ‘Write Cell’.
Else you can loop on your first row, read cell value and change it whenever you want

1 Like

Hi!
Thanks for your answer.

However, when I use the “Read range” activity is throws an error due to the two columns with the same name.
There is other way to loop in the first row of the excel?

just dont get the columns from excel and let read range add the columns like column 1, column 2…

Good afternoon @joaotavares1996

Does the solution in this post resolve your issue?

But I want to do some operations and checks with the column headers (if they have spaces before or after, etc). But the files that are sent to me have columns with the same name. What I want is read the headers and do this operations, and if I found a column with the same name of a previous column in that excel file, change the name of the second one

I cannot use VBA. It was one of my first tries, but the files are in format .xlsx and .xlsb and I cannot convert them to .xlsm in order to use macros and VBA.

@joaotavares1996 Do you know the order of Columns and if so can you put the Order of new Column names in an array of Strings, In this way you can use this array of String to rename the Columns using for Each

Hey, @joaotavares1996

Give this a try:
CheckDuplicateColumnNames.zip (14.9 KB)

Reads the first row (the one with column names) from input excel.
Updates the column names so that no more duplicates appear.
Overwrites the first row with the fixed column names.

then if you cant change the excel before reading in uipath, just create something that will read cell by cell to know the column headers…