# How to get the previous cell information depend on one cell in excel file

dear all,

I have a problem wanna to solve.  I have an excel file as following picture displayed.

The Row 1 like as :
Result
A
A
B
A
A
A
B
A
A
A
A
B
A
A
A
B
A
A
A
A

how could I get the result new Row 1 like
Result
A
B
A
B
A
B
A
B

anybody could give me a help? Thanks a lot for your help !

Hi,

Hope the following sample helps you.

Sample20210618-1.zip (8.6 KB)

Regards,

hey Yoichi

Thanks a lot for your reply. I have another quesiton, if this excel has no Header , it means no row name “Result” , how i get the result .
Previously excel :
A
A
B
A
A
A
B
A
A
A
A
B
A
A
A
B
A
A
A
A

i want get
A
B
A
B
A
B
A
B

Hi,

Can you try the following steps?

2. Modify "Result" to 0 in the expression, as the following.

dt.AsEnumerable.Where(Function(r,i) if(i>0,r(0).ToString<>dt.Rows(i-1).Item(0).ToString,True)).CopyToDataTable`

Regards,

hey Yoichi

I use some example to test , some the result is
A
B
A
B
A
B
A
B
A

the last one A . i don’t need this ,how could i change?

Hi,

Probably i don’t get your requirement correctly.
Can you elaborate algorithm you expect?

Regards?

i use
dt.AsEnumerable.Where(Function(r,i) if(i>0,r(0).ToString<>dt.Rows(i-1).Item(0).ToString,True)).CopyToDataTable`
then i write range the dt

the result is
A
B
A
B
A
B
A
B
A

not
A
B
A
B
A
B
A
B

how could I change ?

Hi,

Thank you for elaborating.