Write Cell for Every Row (Inside a Switch)

Hello everyone! Hoping someone can help me with this.

I have a Switch activity which looks at a Column in a datatable. Inside each item on the Switch, there is a For Each Row.

All of the activities in the For Each Row work perfectly (meaning, the automation only looks at the rows for the specific item), with the exception of Write Cell.

When the automation reaches the second item on the Switch and it gets to the “Write Cell” activity, it starts overwriting the first rows in the datatable (which belong to the first item on the Switch).


This is what I currently have for the "Write Cell" activity:

Assign: “Index” = datatable.rows.IndexOf(row)+2
Write Cell: “C”+Index.ToString

If I remember correctly, this process creates a temporary datatable for each of 3 scenarios. Because of this, the row is getting reset back to zero once the for each loop finishes. What you need is a running index.

Instead of using the datatable row as the index, I suggest to increment the index variable manually.

So put an assign activity at the very beginning of the workflow, assigning index = 2. Then, after each write cell activity, use an assign activity to assign index = index + 1

That doesn’t work because it resets again after each item within the Switch and assumes Index=2 at the start.

I could manually do it within each iteration of the Switch, but I don’t know which row # the second item starts at.

Can you share your workflow? I believe you’re misunderstanding my suggestion. It should not reset to 2 each time if you have your assign index = 2 activity at the very beginning of the entire process. The scope of the index variable would have to be the broadest level

1 Like

This worked! You’re right, I did not have it at the broadest level. THANK YOU!

1 Like

You are welcome.

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