Excel Filter Column

i_planned
excel
activities

#1

Hi,

I have a Excel sheet containing reports. On that sheet, there is a column named as ‘Assigned Date’. I want to filter that column based on week(i.e. From last Tuesday to Monday(Current week)).
Please help me on this.

Thanks in advance!!


#2

@Abishek
Can you explain in generalised format . In general how you want to filter. Suppose if you run the same code next week then you want to filter the data which contains current week date. i.e last 7 days right.

Your excel sheet date column Date is in which format

Regards,
Mahesh


#3

@Abishek

dt1=(From p In dt.Select
where DateTime.Now.DayOfYear-(DateTime.ParseExact(p.Item("Assigned Date").ToString,"dd-MM-yyyy",System.Globalization.CultureInfo.InvarientCulture).DayOfYear)>=0 and DateTime.Now.DayOfYear-(DateTime.ParseExact(p.Item("Assigned Date").ToString,"dd-MM-yyyy",System.Globalization.CultureInfo.InvarientCulture).DayOfYear)<=7 and DateTime.Now.Year=(DateTime.ParseExact(p.Item("Assigned Date").ToString,"dd-MM-yyyy",System.Globalization.CultureInfo.InvarientCulture).Year
Select p).ToArray.CopyToDataTable

dt1- Filtered Data
dt-Original Data.

Sorry if it throws any exceptions, because I have not tested the code :grinning:

Regards,
Mahesh


#4

@MAHESH1

If i run the same code next week, it should filter from last week Tuesday to this week Monday (7 Days).
Date Format: dd-mm-yyyy

Thanks


#5

@Abishek

Try the code and let me know whether it is working or not

Regards,
Mahesh