Anyway that we can rename the duplicate column?
- Using VB code, you can loop through all the column names
- Then add the columns to array or collection while iterating
- Before adding the value to the collection, check the array or collection contains the same value
- If exists, we will have the index , so change the name of the column
This can be done using the VB code in the InvokeCode activity @Sweety_Girl
Let me know if you want code for it
How to change the name of the duplicate column?
Any link for VB code
You can do it on your own as we have lot of threads available online. But here is the code… @Sweety_Girl
Make sure you have installed Microsoft.Office.Interop.Excel package
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Open(File full path, [ReadOnly]:=False)
excel.Visible = True
ws = CType(wb.Sheets(Sheet name), Microsoft.Office.Interop.Excel.Worksheet)
ws.Activate()
Dim MTUsedColumnsRange As Integer = ws.UsedRange.Columns.Count
Dim arrayColNames(MTUsedColumnsRange) As String
For c As Integer = 1 To MTUsedColumnsRange
Dim colName As String = CType(ws.Cells(1, c), Microsoft.Office.Interop.Excel.Range).Value.ToString
If arrayColNames.Contains(colName) Then
colName = colName + "2"
CType(ws.Cells(1, c), Microsoft.Office.Interop.Excel.Range).Value = colName
End If
arrayColNames(c) = colName
Next
wb.Save()
wb.Close()
excel.Quit()
Thank you, I will work it and ping you about it
I have nearly 40+ columns in it
In that they have only 2 column are check the 2column name in if
Here we have like 40+ column, can we apply condition for 40 column in single if
Sure
Do these steps to avoid that @Sweety_Girl
- Open a blank workbook in Excel.
- Go to File > Options > Trust Center
- Click on Trust Center Settings…
- Under Macro Settings , make sure Trust access to the VBA project object model is checked.
Okay done…
Can you post the entire error you are getting?
Have you changed the file path and the sheet name? @Sweety_Girl
thanks buddy its working
Hi @Sweety_Girl
Apart from other solutions guys have given, This is another way of doing it from workflow itself…
Check out the sample attached…
Excel with same column name
The result
Here’s the code for it
I have added some comments as well for you to understand… let know if it’s not clear…
TestData.xlsx (8.8 KB)
ColumnNameCheck.xaml (14.0 KB)
Hope it helps.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.