Insert number sequence in Column A based on column C and D

I need help solving an RPA, I get an excel with column A blank and I need to fill it in based on column C and D.
The condition is:
1st - When columns C and D are filled with numbers, the sequence in Column A is normal

2nd - When blocks with M in columns C and D, the sequence is repeated in Column A.

Note: When there is M in columns C and D, we must have T in one of the columns below until we find another M, or columns C and D are filled with numbers.

Before

After

Hi @Richarlei_Reis

I just tried and it works for me
Use this workflow

Invoke code:

Dim counter As Integer = 1
Dim pause As Boolean = False
dt_result  = dt.Clone()

For Each row As DataRow In dt.Rows
    Dim cVal As String = row("Debit").ToString().Trim()
    Dim dVal As String = row("Credit").ToString().Trim()

    Dim newRow As DataRow = dt_result.NewRow()
    newRow.ItemArray = CType(row.ItemArray.Clone(), Object())

    If pause Then
        If cVal = "T" Or dVal = "T" Then
            newRow("Sequence") = counter.ToString()
            
        Else
			counter += 1
			pause = False
            newRow("Sequence") = counter.ToString
        End If
    Else
        If cVal = "M" Or dVal = "M" Then
            pause = True
            newRow("Sequence") = counter.ToString
        Else
			pause = False
            newRow("Sequence") = counter.ToString()
            counter += 1
        End If
    End If

    dt_result.Rows.Add(newRow)
Next

' Assign the result back to dt if needed:
dt = dt_result

Input and output:

Please do mark it as a solution if it helps you

Happy Learning :innocent:

I’m getting this Exception

I’m sending you the project.

I’m happy to try to help me

Insert number sequence.zip (16.7 KB)

Hi,

It’s necessary to set variable (dt_input) at DataTable property of ReadRangeWorkbook activity. Can you set it?

Regards,

1 Like

@Richarlei_Reis

As @Yoichi said make sure add dt_input to the read range workbook

and also make sure to add add headers

Output:

Hope this helps!

Yes, that’s right, Thank you!