Loop for compare current row & next row1, row1 & row2, row2 & row3.... last row

Hello all,

I need compare current row & next row1, row1 & row2, row2 & row3… last row as below image
And I have to do it manually so many times. How can I use loop ?

DtPhu.Rows(idx+1).Item(2).ToString=DtPhu.Rows(idx+2).Item(2).ToString And Left(DtPhu.Rows(idx+1).Item(1).ToString,6)=Left(DtPhu.Rows(idx+2).Item(1).ToString,6)

1 Like

doesnt this solve your problem? this code is in loop right? @anh.nguyen

Yes, code in loop of DLV and if DLV have a lot of row. i have to manual compare rows as image & i don’t know last row

image

you can check last row using if statement @anh.nguyen

If:
DtPhu.Rows.Count = idx+1

1 Like

Last time you helped me compare row1 & row2 in case Customcode “C00392,C01085,C00600,C01017,C01069”. And compare row1 & row2

(RowPhu.Item(2).ToString=DtPhu.Rows(idx+1).Item(2).ToString) And Left(RowPhu.Item(1).ToString,6)=Left(DtPhu.Rows(idx+1).Item(1).ToString,6)

row2 & row3

DtPhu.Rows(idx+1).Item(2).ToString=DtPhu.Rows(idx+2).Item(2).ToString And Left(DtPhu.Rows(idx+1).Item(1).ToString,6)=Left(DtPhu.Rows(idx+2).Item(1).ToString,6)
image

Problem: i don’t know how many row to continue compare. So I want ask have other way, can use loop ?

DLV015.xaml (1.4 MB)

1 Like

ok, i will help when im free,

1 Like

A technique for row n & n+1 is to ommit in the loop the first row:


grafik

row("Colname").ToString.Trim.Equals(yourDataTable.Rows(idx)("Colname").toString.Trim)

then we are using the n+1 row and compare with the row before that we get with
yourDataTable.Rows(idx)

as the index starts with 0 we fetch always the previous row

However, while looking to your data, representing a lot if duplicates we do feel that the use case maybe target something else. So elaborate more on your initial requirement and what is to achieve.

Maybe grouping the data / duplicate checks can help to reach the goal

1 Like

Thank you, I want compare Group1-5 row1 & row2, row2 & row3… last row.
I do as you guide but the lines are always equal

image

check the used column index and adapt it if it is needed
kindly note: column index is 0 based. first Col = 0, second Col = 1 …

@anh.nguyen try this
DLV015.xaml (2.0 MB)

1 Like

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