Hi there, I’m looking to pull a string from a datatable and then search that same data table for a similar string with a different year in the name.
For example - IF “product name 2020” contains “2020”, then find “product name 2019”
I’m using a read range to populate the datatable, then I’m using a For Each Row to find which rows contain “2020”, at this point I’m storing the other data I’m interested in.
Within this first For Each Row I’m using a nested For Each Row, to search the datatable for names similar to the current row name. I then want to use an IF condition determine whether these values match, using regex to allow for the difference in year.
I’m struggling with the regex necessary to create the correct IF condition. Any help greatly appreciated
Hi
i hope we can simply check with a contains activity
like this in if condition row(“yourcolumnname”).ToString.Contains(“2020”)
if this condition passes it will goto THEN part where we can include any activity we want
hope this would help you
Kindly correct me if i have understood the query wrongly
Cheers @jakegill
I’m using the contains method as you have suggested in the first IF loop. This gets me a row(name) that contains “2020” - let’s call it ‘Product Name 2020’.
I’m then using a nested For Each to search through the data table again to find a similar product with a name that almost matches except with a different year - e.g. Product Name 2019 - let’s call this ‘Product Name YYYY’.
I want to check whether the second search pulls a value that matches the first search. I’m not sure how to use regex to match these names considering they have different years.
Sure, but I think there would have to be a stage in between that separates the product name from the YYYY so I’d be able to use the product name to search. This was why I originally thought of regex to find a partial match where most of the product name matches but the year at the end can vary.
Hi Pal, thanks for your help with this. I’m using the string.contains method for both For Each Rows as you’ve suggested. I’ve cleaned the data in excel so I can avoid regex. It’s now working as hoped.