Excel - Get Specific Range

Hi,
I have a scenario like below and need help,

image

I need to get the range of Plant codes as a datatable based on the Company Code. The company code is my input. How can I get the plant codes as a datatable for the Company Code? For example: If the company code is 4000, The Plant code I need to get should be 4551-4556 as a datatable.

Thanks in Advance

1 Like

@esakki1612 build one datatable-
In for each row in datatable
If currentrow(“company code”)=“4000”
Then add that datarow to datatable.
Outside for each remove datacolumn of company code from datatable

Hi @esakki1612 ,

Could you give this workflow a try and let us know if it works out for you?
image

image

//To find row which contains code
dt.AsEnumerable().ToList().FindIndex(Function (x) x("Company Codes").toString.Equals("5000"))
//Collects rows until next code
dt.AsEnumerable().
	Skip(int_rowIndex).
	TakeWhile(Function(tk,i) i=0 OrElse IsNothing(tk(1)) OrElse String.IsNullOrEmpty(tk(1).ToString.Trim)).
	CopyToDataTable()

FetchRowsBasedonCode.xaml (8.3 KB)
Book5.xlsx (8.8 KB)

Kind Regards,
Ashwin A.K

2 Likes

Thanks alot Ashwin. It Worked

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