If a row contain a string, then perform an activity only once

Hi,

Here is what I’m trying to automate:

image

  • Filter City
  • If City contains Tokyo then perform an activity (only once, eg: Write range)(Not in loop)
  • If City does not Contains Tokyo then do nothing

Thanks a lot :slight_smile:

Hi @Bhanu_Rathore

Please use the below Linq expression!

If you want to check the city exits means Try Removing CopyToDatatable it will result in Boolean or If you want to write the Value use CopyToDatatable And WriteRange

yourDT.AsEnumerable().Any(Function(x) x(“City”).ToString = “Tokyo”).CopyToDatatable

Regards

1 Like

Hi

Hope these steps would help you resolve this

—use a excel application scope and pass the FilePath of the excel and inside the scope use a read range activity and get the output as a datatable named dt

—use a FILTER DATATABLE activity and pass the above dt as input and inside the activity mention the column name in double quotes and use a condition like = and value as “Tokyo”

Get the output datatable as dt again

—now this dt will have only the city with Tokyo as value

—then use a write range activity to write to a excel

Cheers @Bhanu_Rathore

Hi @Bhanu_Rathore

For your case,

U can try this way as well.

Use lookup datatable activity to lookup the Tokyo value in city

There is property in lookup datatable activity known as rowindex

If the value is there rowindex will return the rowindex where the value is in datatable

Otherwise if the value is not present , it will return zero

So in the if condition u can make the condition with rowindex as

rowindex<>-1

If this is True , execute the activity

Else do nothing

Mark it as solution if it helps you around

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

Hi @Palaniyappan

Sorry I didn’t understand. Where is “If condition” in this?

What if there is no Tokyo in file?

If there is no Tokyo then I want to skip next 20 steps that I would do if tokyo is present in file.

Hope you get it. Thanks :slight_smile:

Filter datatable activity will actually fetch the exact matching data and remove the other stuffs
So this datatable when filtered with Tokyo it will give only the Tokyo valued rows

Cheers @Bhanu_Rathore

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