IF statement not finding matches that exist in source file

I have an IF statement that looks to see if a row of data in a data table has a match for a specific column. When using a test Excel file as the source data the process works exactly as expected. However, when I switch to the production Excel file the IF statement does not find any matches.

High level of the process:

  1. I set the varCurrentMonthName variable at the beginning to equal the current month at the time the robot is running
  2. I pull in the source data (from an Excel file) and output it to a data table, dtFileReviews
  3. I then use a For Each to cycle through each row of data and perform certain actions (in the Flowchart) when a row has a month in the Close Month column that matches varCurrentMonthName

The test file and the production file have the exact same structure, yet when the bot attempts the process with the prod file it finds no matches. I have gone through the debug process and confirmed that the data is being pulled in the same with both and the columns, etc are all the same. I am completely stumped as to why it will not work with the production source file. Is there something with the properties of the prod file that I should be checking?

I have a separate bot that uses this same source file that points to a different month column (to setup the items that this new bot is now trying to close), and that setup bot works perfectly.

Here is the portion of the sequence that contains the IF:

Could you check whether any unwanted space is there in the rows in production. Better you can compare both files and check whether the length of values are dame or not. Also check whether the data is case sensitive.

Yes, I have already done that. In fact, that was the first thing I checked as I had wondered the same thing.

@jesse.paplanus Try this

row("Close Month).ToString.Trim.equals(varCurrentMonth.Trim)

Are you sure it is always going to else block. If not,Please run in the debug mode or keep some message box in then, else block and check the execution

As you mentioned the flow is not working only with production data, it sounds strange. Also if both the data is same it should work fine.

Are you getting error or just proceeding without finding any matches?? Can you print the values which you usediside the if condition to a message box and the length of both values.

I suspect some Anonymous values are getting added

I thought this too, which was why I initially checked for spaces. At the end of the entire process I have the bot save the data table to an Excel file that contains all rows and columns, plus a results column of what it did with any matches. Even this file shows no other spaces or extra characters in the Current Month column for any row, not just those that match the current month. I will try ushu’s idea of using Trim and see what happens.

Sure…you can try that…Trim will help to remove the unwanted spaces in the string. As you confirmed there are no space issues not sure whether trim will here.

If it’s not working is it possible to share the excels here??

Unfortunately this did not work, but thank you for the suggestion.

@jesse.paplanus May I know is there any error showing at if

Also, can you try this take a message box before if and try to print row(“Close Month”).ToString

Remove the Break activity from the Else flow.

Break will exit the For loop so if the first row doesn’t contain a match, then you won’t check the rest of the rows either.


Thanks @ptrobot, that was it! My test file had the May rows at the top, but my production file they are sorted in true month order. This makes sense. I had the Break activity in there because my flowchart had been looping through the last matching row over and over again and that was the solution I found to get it to stop. I believe when I first put it together the flowchart was outside the IF but still part of the For Each, but has since been moved in. I re-ran the process and it is no longer looping through the last matching row with the break removed, and the file is cycling through all rows of data regardless of sort order.

1 Like

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