Checking whether a cell of a certain row has a keyword

Dear all,

I am trying to find out:

  1. whether the keyword is in a cell of a certain row
  2. what is the position of that cell

How can i do that?

Hi @avene

Is it always the same column that you would scan for the specific keyword?

If so, you could follow those steps:

  1. Load your Excel file to the Data Table by using Read Range activity.
  2. Iterate through every row of the Data Table by using For Each Row activity (the one under Programming->DataTable)
  3. Check your condition inside of the loop by using this line of code (when row is each item of the loop):
    row.Item("yourColumnName").ToString.Contains("yourKeyWord")
    This will return True or False, depending on whether the keyword is present in the particular column of the current row.

The rest is figuring out the current index of the row you are iterating through.
This can be done with:
yourDataTableVariable.Rows.IndexOf(row)
This will return an Integer value for the current row.

3 Likes

Hi! thanks for the reply :slight_smile:

For my project, I am looking at the same row that I would scan the specific keyword.
so would it work if i do row.tostring.contains(“keyword”)?

To access any item in a specific Data Table with a simple assign activity without any loops, the syntax would look like this:
yourDataTable.Rows(yourRowIndexAsInteger).Item("yourColumnName").ToString.Contains("keyword")

Example:
DataTable.Rows(0).Item("Cars").Contains("Audi")
This will return True if the column “Cars” in the first row of the data table contains keyword “Audi”.

As @loginerror suggested you can read all data in datatable then iterate using for each row,
and if you wants to search in a complete row you can use
dataRowA.Itemarray.toList().contains(“Keyword”)

If it returns true
find column index using dataRowA.Itemarray.toList().indexOf(“Keyword”) and
Row index using dataTable.Rows.indexOf(datarowA)

Thanks

1 Like