sorting data within 90 days from today

annadinesh

Board Regular
Joined
Mar 1, 2017
Messages
105
Dear Experts

I am trying to Sort A List which are within 90 days with the following code but failed.


Range("A3:O65536").AutoFilter Field:=5, Operator:=xlAnd, _
Criteria1:="<" & Date - 90

Please check and help



Dinesh Saha
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Dear Dinesh Saha Please Try This.

VBA Code:
With Worksheets("Sheet1").Range("A1:O1").EntireColumn
        .AutoFilter
        .AutoFilter Field:=5, Criteria1:=">=" & Date - 90, Operator:=xlAnd, Criteria2:="<=" & Date
    End With
 
Upvote 0
Dear Dinesh Saha Please Try This.

VBA Code:
With Worksheets("Sheet1").Range("A1:O1").EntireColumn
        .AutoFilter
        .AutoFilter Field:=5, Criteria1:=">=" & Date - 90, Operator:=xlAnd, Criteria2:="<=" & Date
    End With
Sorry to say that the code is also not working,

My Data

Customer NameModelREGD NO.Sale Date
Suk Bahadur MagarGrand i10 NIOS 1.2MT Kappa SportzWB74BL3566
16.08.2022​
Tapan Kumar PyneGrand I10 Nios 1.2mt Kappa SportzWB72AB0597 27.06.2022
Biplob SarkarGrand I10 Nios 1.2mt CorporateWB74BL0135 16.07.2022
Naresh KumarCreta 1.5 CRDi MT EPB15X3020
12.08.2022​
Siddartha Kumar PradhanVenue 1.2 Kappa Mt SSK05P3661 01.07.2022
Chandan Ghoshi20 N Line N6 1.0 Turbo GDI iMTWB74BL2023
17.08.2022​
Prabin Chandra MoktanCreta 1.5 Mpi Ivt SxWB74BL0821 16.07.2022
Kamal ThapaGrand I10 Nios 1.2mt Kappa AstaWB74BL0597 23.07.2022
Partha MallickVenue 1.2 Kappa Mt SxWB74BL1004 25.07.2022
Phurtengy SherpaCreta 1.5 MPi MT EXAF370715
19.08.2022​
Bikash AgarwalCreta 1.5 MPi IVT SX(O) SEWB74BL2324
24.08.2022​
Uma SalesVENUE 1.5 CRDi MT SXWB74BL1921
10.08.2022​
Swati ChakrabortyCreta 1.5 MPi MT S+ SEWB74BL3299
19.08.2022​
Abhishek SahaVERNA 1.5 MPI MT SX(O)WB74BL6297
16.08.2022​
Kakali BhattacharjeeGrand i10 NIOS 1.2 AMT Kappa AstaWB74BL3514
12.08.2022​
Saria ConstructionI20 Asta 1.2 Kappa MtWB74BL1551 29.07.2022
Shankar Lal MaheshwariAlcazar 1.5 AT Signature(O) 7SWB72AB2929
30.08.2022​
Pramod PradhanVenue 1.2 Kappa Mt S(o)WB74BL1617 26.07.2022
Debabrata GhoshCreta 1.5 MPi IVT SX(O) SEWB74BL1954
03.08.2022​
Arup DasVenue 1.2 Kappa Mt S(o)WB74BL2849
11.08.2022​
Karma Tenzing DukpaVENUE 1.2 Kappa MT SXWB79B1300
08.08.2022​
Lakpa Norbu SherpaVENUE 1.2 Kappa MT SWB74BL2676
16.08.2022​
Prajwal Nirolai20 Asta(O) 1.2 Kappa MTWB74BL5020
30.08.2022​
Goutam BagchiGrand I10 Nios 1.2mt Kappa SportzWB74BL2007 11.08.2022
Arpan RajputGrand i10 NIOS 1.2MT Kappa SportzWB74BL4020
12.08.2022​
Ganesh SharmaVENUE 1.2 Kappa MT SXWB74BL2846
12.08.2022​
Ashish PrakashVenue 1.2 Kappa Mt SxBR50X1989 12.08.2022
Biswadeep ChowdhuryVenue 1.0 Turbo Imt Sx(o)WB74BL5010 15.09.2022
Biswajit ChowdhuryVENUE 1.0 Turbo iMT SX(O)WB74BL5010
15.09.2022​
Shankarshan Sarkari20 Sportz 1.2 Kappa MT22BH2535C
11.08.2022​
Rashmita Thakurii20 Magna 1.2 Kappa MTWB74BL4016
16.08.2022​
Amar Milan ChowhanVENUE 1.2 Kappa MT SWB74BL2840
12.08.2022​

I want when i press the command button the datas which are 90 days back from todays date will show in Coloumn SALE DATE.

Please Check and Help.
 
Upvote 0
Hi Dinesh Saha,

it's not clear by posting the code if it's Dates in there (right bound) or Dates formatted as Text (left bound).

Code for "real" dates could look like
VBA Code:
        Range("A1").CurrentRegion.AutoFilter field:=4, Criteria1:=">=" & CLng(Date) - 90
To convert the dates you may try

VBA Code:
Sub DoConvert()
  
  Dim rngCell     As Range

  For Each rngCell In Range("D2", Cells(Rows.Count, "D").End(xlUp))
    If IsNumeric(rngCell) And Not IsEmpty(rngCell) Then
      rngCell.Value = CDate(rngCell.Value)
    End If
  Next rngCell

End Sub

Both codes work on the active sheet in Excel.

Ciao,
Holger
 
Upvote 0
Solution
Hi Dinesh Saha,

it's not clear by posting the code if it's Dates in there (right bound) or Dates formatted as Text (left bound).

Code for "real" dates could look like
VBA Code:
        Range("A1").CurrentRegion.AutoFilter field:=4, Criteria1:=">=" & CLng(Date) - 90
To convert the dates you may try

VBA Code:
Sub DoConvert()
 
  Dim rngCell     As Range

  For Each rngCell In Range("D2", Cells(Rows.Count, "D").End(xlUp))
    If IsNumeric(rngCell) And Not IsEmpty(rngCell) Then
      rngCell.Value = CDate(rngCell.Value)
    End If
  Next rngCell

End Sub

Both codes work on the active sheet in Excel.

Ciao,
Holger
ITS WORKING, THANKS A LOT
 
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,603
Members
449,174
Latest member
ExcelfromGermany

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top