The Scenario :
dataTable A = [“A”,“B”,“C”,“D”,“E”]
dataTable B = [“A”,“B”,“C”,“D”,“E”,“F”,“G”]
1st For each loop{
dataTable A
2nd For each loop{
dataTable B
}
}
As per for each loop behaviour,
when 1st each loop starts, it takes 1st element and searches it in 2nd dataTable. If it matches it breaks [because condition is set by me] the loop and again loop takes 2nd element and searches starts from 1st element, 2,3,4… of 2nd dataTable…
But my requirement is: after breaking the loop, when 1st loop takes 2nd element to search in 2nd dataTable, i want that loop to search from 2nd element as beacause 1st element is already matched with 1st element of 1st datatable… and it goes on untile datarow count.
As long as you don’t break out of the first loop it won’t start over again at the first element.
And you want to search all the elements in the second loop because you don’t know which element will match. It won’t necessarily be the first element from the 2nd array that matches. Your requirement of skipping the matched element is pointless and extra complexity that gains nothing.
If you insist on doing that, you’ll need to store the indexes to skip in an array, and then put an IF with NOT yourArray.Contains(index) so it’ll only check the row if it isn’t in the already matched list (yourArray).
I have that requirement so…, where I have to loop through sheet 1 column B which is in dataTable and match it with another sheet’s column B and if value matches need to grab the column C value and paste into 1st sheet’ A column.
But if the row in DT2 matches the first row from DT1 it won’t match the second row from DT1 so why do you need to skip it? Skipping it gains you nothing.
Is a for loop necessary inside a for? Since you cannot delete rows from the dt you are using, you can first create a new table with dt.copy and delete it from there.
You have to stop thinking of it this way. It’s not about where it starts. If the matched element is the 6th element you don’t want to start at the 7th element, you want to start at the 1st element and skip the 6th element.
Actual Requirement: I need to compare two column from two different sheets and if match is found need to copy the cell value and paste into another work sheet on the comparing sheet and if value is not match leave the cell empty and repeat the process.
Could you maybe provide input and Output example data for this Scenario? If you could provide us the Excel Sheets it would be quicker for us to assess the logic and provide you a better solution.
On a glance of your requirement, it does seem that you could perform these task using Join Datatables Activity as well, and then performing the required update using a Single For Each Activity.