Check if a string exists in column

image

I have following table in excel.

I need to check whether First Column : Fruit consists Apple or Banana.

I tried to use this image

But it goes to else.

Please help me, what i am missing here.

hi @prabin_poudel

use trim may be a space is the problem.

row("Fruit").tostring.Trim.ToLower.equals("apple")

Ajay

1 Like

@prabin_poudel no prob you got this!

change the condition to row(0).tostring = "Apple"

I like @Ajju’s method better (the .Trim and .ToLower can save you big time in the long run) his method removes unwanted spaces at the beginning and end of the string, and it also eliminates any issues that could pop up from case sensitive items.

Just as a heads up - you can use either row(“Fruit”) or row(0) and you will still use the first column. The only benefit of using row(0) in this case is if there was extra spaces in your column header.

I Tried to use Ajju answer but still it is going to else. I just tried to print the row(“Fruit”).tostring and it return banana which is the last item in excel table fruit column

I tried to use it but still it is going to else. I just tried to print the row(“Fruit”).tostring and it return ‘banana’ which is the last item in excel table fruit column

@prabin_poudel

In first iteration, it will go to the Then part and in other two iterations it will go to the Else part.

And also show me the expression how you wrote in IF condition.

row(0).ToString.Contains(“Apple”)

I Tested above code working fine for me

Check whether AddHeaders is marked on Read Range activity. or else it will take the first cell as an item.

Hi Guys, i have used @Ajju solution, It is working fine now .

Thank you

2 Likes

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