Add data row after finding the text

Hi,

I need to add data row after finding the text. Eg. my data table is:

Nr
1
2
3
4
5

If I find 3 I would like to add data row with text “”. Result shoud be

Nr
1
2
3
“”
4
5

How could I do it?

Hey Krzysztof,

I think you would need two things:

  • An integer (let’s call it “index”) to keep track of where you’re at as you iterate through rows with value 0
  • A Data Table (let’s call it “dt”)

Use a Do While activity with the condition: “index < dt.Rows.Count”

Use the Do While to iterate through the indexes of the data table. Check each row for the value you mentioned:

If dt.Rows(index)("Nr").ToString = "3"

If True, insert a new row with the method:

dt.Rows.InsertAt(dr, index + 1)
and
index = index + 1
(Because we want to skip the row we just added during the next iteration)

Finally you want to increment the index by + 1 to keep your loop moving

If you only want to add a row at the first occurence of “3”, then you will have to add additional logic in your Do While condition to break the loop.

I hope this helps you work towards a solution. There are other ways which would involve creating a list of row indexes where your row contains your value, but I think this is the most readable solution for now.

Edit: my original answer had “Nr” column as type Integer. Updated to use String as your question specified Text

1 Like

Hi,

I do not understand this part:
image

I have free version uipath and I have not multiple assign activity.
You do not have in your variable any “newRow”. This variable is not use later.

I also can not find this activity:
image