Feb 22 2022 07:39 PM
Hi, I have managed to extract a particular set of data using advanced data (VBA) but was wondering how can I take it a step further by sorting the extracted data by date with VBA instead of manual data > filter> sorting?
E.g.
Customer A bought 10 on 10-Jan
Customer B bought 10 on 11-Jan
Customer C bought 10 on 9-Jan
When using advanced filter, the sequence will remain in order of the cells (A B C). I was hoping for the VBA to sort CAB before copy the data to the "CopyTo" range -> according to date of transaction. I have managed to add in a timestamp to when the data is entered. Do let me know if you have an idea. Thanks!
Feb 23 2022 11:54 AM
Maybe as an additional code
ActiveSheet.ListObjects("Table_from_Database ").Range. _
AutoFilter Field:=5, Criteria1:=">=" & CLng(CDate("01.02.2022")), Operator:=xlAnd, Criteria2:="<=" & CLng(CDate("23.02.2022"))
or as a macro
Option Explicit
Sub Filtern()
Dim vDat As Variant
vDat = InputBox( _
prompt:="Date:", _
Default:=Format(Date + 6, "dd.mm.yy"))
If vDat = "" Then Exit Sub
vDat = CDate(vDat)
Range("A1").CurrentRegion.AutoFilter _
field:=3, Criteria1:=">=" & CDbl(vDat)
End Sub
Example file for this macro is included.
I know I don't know anything (Socrates)