Check if specific column exists in Excel

Hello Guys

How to check if a specific column exists after you read the data from excel? Because I have an activity that will create additional column, however, if the bot fails after creating that column and then re-run it, it will fail because the column already exists. Is there a way to check if the column exists then delete it or skip the add column activity? Thanks

Hi @Callos_James_AU,

You can use the below syntax to check if a specific column is present or not:
Datatable.Columns(0).ColumnName.ToString.equals(“column name u want to check”)

1 Like

@Callos_James_AU
Consider your data table is dtData and your column name to be checked is saved in a variable named strSearchColumn. Use

dtData.Columns.Contains(strSearchColumn)

The output of this expression will be a boolean value denoting the existence of the column.

4 Likes

Thanks for this @shivagowdavarad!

1 Like

Thanks for this @Madhavi! It works :slight_smile:

1 Like

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