-
Oct 6th, 2021, 02:42 PM
#1
[RESOLVED] Autofilter Criteria Array Parameters
In this autofilter statement
.Range("$A$1:$D$233").AutoFilter Field:=1, Operator:=xlFilterValues, Criteria2:=Array(2, "9/1/2021")
what does the bolded 2 represent?
And how can I change the Array() portion to use a string variable which contains a date?
Last edited by MartinLiss; Oct 6th, 2021 at 02:46 PM.
-
Oct 6th, 2021, 03:39 PM
#2
Re: Autofilter Criteria Array Parameters
I figured out the second part of my question.
Array(2, strDate)
but strDate need to be mm/dd/yyyy
-
Oct 6th, 2021, 03:58 PM
#3
Re: Autofilter Criteria Array Parameters
-
Oct 7th, 2021, 04:05 AM
#4
Re: Autofilter Criteria Array Parameters
but strDate need to be mm/dd/yyyy
maybe
Code:
strdate = "9/1/21"
.Range("$A$1:$D$233").AutoFilter Field:=1, Operator:=xlFilterValues, Criteria2:=Array(2, Format(CDate(strdate), "mm/dd/yyyy")
should fix issues, but i just hate ambiguous dates
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 7th, 2021, 05:16 AM
#5
Re: Autofilter Criteria Array Parameters
The question is not which output-format to use, but which format the input-values have
Is "9/1/2021" the 1st of September 2021 or the 9th of January 2021?
If the Input-Format is known, and definitely doesn't change, i'd rather parse through the Date-String, assign separate values for day, month and year, and then use DateSerial to recombine it into a valid, local Date
In case of String-Dates i'd go with the Split-Function
Code:
Dim arrDate() As String
Dim datDay As Long
Dim datMonth As Long
Dim datYear As Long
Dim MyDate As Date
arrDate=Split("9/1/2021","/")
'I'm assuming the Sample date is 1st of Sep.
datDay=CLng(arrDate(1))
datMonth=CLng(arrDate(0))
datYear=CLng(arrDate(2))
MyDate=DateSerial(datYear, datMonth, datDay) '--> the local variables are just to demonstrate. You could use the Array-Memebers directly in the Function
'Use whatever Format of MyDate you need in subsequent Functions
Last edited by Zvoni; Oct 7th, 2021 at 05:21 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 7th, 2021, 07:34 AM
#6
Re: [RESOLVED] Autofilter Criteria Array Parameters
Thank you all for your suggestions and jdc2000 for the link.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|