Using Multiple For Each toLoops to obtain a value

HI all

I had a body of text in a string variable. I need to see if that variable contains a word found in column A, ‘Category’ - so if the word ‘ESAP’ is found, I create a folder of that name and end the activity. However if no word is found in Column A, I need to look in Column B ‘Category Keyword’. If a word is found there, I need to create a folder of the category name in Column A e.g if the word ‘IE Approval’ is found in Column B (Row 5), I would need to create a folder called ‘Payment cert’ (value from Column A). All the values in column B will be separated by a comma.

I think I can see how if a value is found in column A would work, I’m not sure how to deal with if a value is found in column B, how I would relate it back to the word in Column A

Any help would be really appreciated :slight_smile:

Hi @jordrowley

Check the attachment for your reference

BlankProcess14 (2).zip (23.1 KB)

You can use linq statement to match, this will replace placing multiple foreach
sample Linq Code :

YourDatatable.AsEnumerable().Any(Function(x) x("Category").ToString.ToUpper.Contains(YourVariable.ToString))

This will return a Boolean Value

So you can place the logic

Mark as solution if this helps


1 Like

Hey @ksrinu070184 sorry for the late reply. This looks really, really good. I’m having a go with it now.

Please can I ask one question. This looks like it would work for the ‘Category’ column, would I get it to move on to the ‘Category Keyword’ column?

Thanks so much


Place a IF condition and check, If this false, the place another If condition this time change the statement as below

YourDatatable.AsEnumerable().Any(Function(x) x("Category Keyword").ToString.ToUpper.Contains(YourVariable.ToString))

So this will give the same result

Hope this is clear

Mark as solution if this helps you


1 Like

Hey @ksrinu070184 it helps loads - it’s brilliant

Have one last cheeky question if it’s possible. So if it finds the ‘identifier’ in this example ‘Red’ is there a line of code that will tell me what the associated Category is - in this example that would be ‘Colours’ - I would then get the process to create a folder called ‘Colours’ (the folder name always has to be the name of the Category, not the name of the Identifiers)

Thanks for all of your help,

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