Search for specific string in Excel and find the last value

You need another If activity outside the first one.
So it says this:

If row(0).ToString.Trim.ToUpper = "YES"
    If row.ItemArray.Contains("***")

That way, you will look at the first column for “yes” first. Unless I am wrong on your requirement, but let me know if I am.

The part with the error:
I’m not sure what that error says, but let’s change it slightly…
You need to check if it is a number first, so do something like this:

If IsNumeric(row.Item(row.ItemArray.Count-1))
    If CDbl(row.Item(row.ItemArray.Count-1)) > 0

That way, you can do somthing if the value is not a number and do something if the value is positive or negative.

Let me know if you still getting errors. I changed it to use the .Count of the itemarray as the index for the row - so it will get the last item in the row. I’ll check why .itemarray.last didn’t work later, when I get a chance.

I hope this helps.

Regards.

1 Like

Hi @ClaytonM

item.contains(****) i am getting true value
Please find attached workflow screenshot and let me know where i am doing mistake to get the value

What you have looks correct. If it is True, then that must mean the row contains 3 stars.

You can put this in a message box to see the entire row if you would like to see the row it is looking at:
String.Join(",",row.ItemArray)

Regards.

1 Like

Yes @ClaytonM
in message box now i am able to see below attacment
image

but how to get the last value and store into a variable

I see there are extra columns in the row, so what you will want to do is only take the items where it is not equal empty string. There are a few ways to do this, but I will just show you how to use .Where() with the itemarray to only take the items.

So you can just store the last item to a string or double type variable using an Assign activity:
Assign activity: lastValue = row.ItemArray.Select(Function(x) x.ToString.Trim).Where(Function(x) x <> "").Last

So, .Select() is used to trim all the items in the array, then .Where() is used to only take the items that do not equal empty string. .Last is used to take the last item in the array.

If you want to store this to a Double type, then you can use CDbl() around it, or since your number is in a particular format with the decimal and comma, you can try using Double.Parse()

For information on Double.Parse, take a look here: Double.Parse Method (System) | Microsoft Learn
or here: Search results for 'double.parse' - UiPath Community Forum
or google.

(you might need the format as part of the parse, and I’m not 100% sure on the syntax)

After, you get the last item stored to a variable, then you change your If condition that looks at the last item to simply see if it is > 0
If activity: condition: lastValue > 0

Just remember though that you must parse your value to a double type, or it won’t be a number.

Regards.

Thank you so much for your help

1 Like

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