Better way to sort through a Datatable?

Hello and Greetings!

I still have lots to learn still. I am pretty new to UIpath and the forums so I apologize if this is a little rough. I don’t generally post to forums.

I am currently working on creating an automation to assign tasking in a system. To do this I have to make a lot of comparisons by reading an excel spreadsheet that is generated by the system. As I am new I cannot upload a copy of my sequence so I’m going to do my best to describe what I am doing.

Currently I have the robot pull a copy of the excel spreadsheet then cycle through the sheet and create new sheets based off a nested if statement.

Currently setup roughly like:

If (row(0).ToString.Contains(“x”))
write row to sheet in excel workbook
increment counter for cell

else if(row(0).ToString.Contains(“y”) and row(1).ToString.Contains(“z”))
write row to sheet in excel workbook
increment counter for this sheet

  else if(row(0).ToString.Contains("y") and not row(1).ToString.Contains("z"))
  write row to sheet in excel workbook
  increment counter for this sheet

  else
   invoke fallout sequence

Now this creates a nice little excel workbook for me but now I need to add names into it for error checking and sending a copy to a coworker. I have the names set up as an array of strings. I could add an additional statement into each if and have the name get added to a cell but then I feel like I need an additional check to make sure I’m not going out of bounds of the array and to reset the index of the array back to 0 once it’s reached the end. That would mean an additional if in each else if. I feel like there should be a better way to do this and that nesting that many if’s is just asking for trouble.

What I am wondering is if there is possibly a better way to do this? I was originally thinking to sort the sheet by using a switch case but I can’t seem to get the switch to work the way I want it to.