ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   executing an autofilter in VB (https://www.excelbanter.com/excel-programming/345565-executing-autofilter-vbulletin.html)

[email protected]

executing an autofilter in VB
 
Hello everyone,
I tought I could find the answer by myself and not disturb you, but it
have 2/3 days that I've been searching solutions to my problem through
the NG and did not find any anwser.

Here is my problem :
I have programmed an autofilter under VB in Excel...the thing is that
when I run it from a userform...the autofilter is empty. And when i
have a look in the "personnalised"...my criteria are correct..so I
click on the OK button and finally the filtered data are displayed.....
What I don't understand is why those data are not displayed
automatically.

Here is my piece of VB program (which is very basic VB!!!) :

Rows("5:5").Select ' this select the entire line where there are the
titles of the columns
Selection.AutoFilter
Selection.AutoFilter Field:=9, Criteria1:="=" &
Format(Extractions.LDDate1.Date, "dd/mmm/yyyy"), Operator:=xlAnd,
Criteria2:="<=" & Format(Extractions.LDDate2.Date, "dd/mmm/yyyy")

nota : extractions is my userform, LDDate1 & LDDate2 are the databox
which gives the criterion for the autofilter.

thanks in advance for anyhelp, I really don't know what to do....

Angélique


Tom Ogilvy

executing an autofilter in VB
 
Selection.AutoFilter Field:=9, Criteria1:="=" &
cdate(Extractions.LDDate1.Date), Operator:=xlAnd,
Criteria2:="<=" & cDate(Extractions.LDDate2.Date)

would be a guess
--
Regards,
Tom Ogilvy



wrote in message
oups.com...
Hello everyone,
I tought I could find the answer by myself and not disturb you, but it
have 2/3 days that I've been searching solutions to my problem through
the NG and did not find any anwser.

Here is my problem :
I have programmed an autofilter under VB in Excel...the thing is that
when I run it from a userform...the autofilter is empty. And when i
have a look in the "personnalised"...my criteria are correct..so I
click on the OK button and finally the filtered data are displayed.....
What I don't understand is why those data are not displayed
automatically.

Here is my piece of VB program (which is very basic VB!!!) :

Rows("5:5").Select ' this select the entire line where there are the
titles of the columns
Selection.AutoFilter
Selection.AutoFilter Field:=9, Criteria1:="=" &
Format(Extractions.LDDate1.Date, "dd/mmm/yyyy"), Operator:=xlAnd,
Criteria2:="<=" & Format(Extractions.LDDate2.Date, "dd/mmm/yyyy")

nota : extractions is my userform, LDDate1 & LDDate2 are the databox
which gives the criterion for the autofilter.

thanks in advance for anyhelp, I really don't know what to do....

Angélique



A.PEIGNE

executing an autofilter in VB
 
Hello Tom,
Thank you for the try, but that did not work either (and on the 1st
criteria, it switch the day with the month).

I put for criteria 1 & 2 : Format(Extractions.LDDate1.Date,
"dd/mmm/yyyy" in order to avoid the switching in between the month and
the day (which happens with your solution).

I really don't understand why each time i run this VB, i still have to
go in the sheet and the personnalised filter to click OK!!! Very weird.

Otherwise, would you have an other idea of encoding a little something
that would filter that sheet in between 2 asked dates?

Thanks a lot

Angélique

Tom Ogilvy wrote:
Selection.AutoFilter Field:=9, Criteria1:="=" &
cdate(Extractions.LDDate1.Date), Operator:=xlAnd,
Criteria2:="<=" & cDate(Extractions.LDDate2.Date)

would be a guess
--
Regards,
Tom Ogilvy




Tom Ogilvy

executing an autofilter in VB
 
cdate will convert the date to a date serial in accordance with the date
settings for your machine.

I have never heard of it switching the month and day unless you have
reversed them from your regional settings.

--
Regards,
Tom Ogilvy



"A.PEIGNE" wrote in message
oups.com...
Hello Tom,
Thank you for the try, but that did not work either (and on the 1st
criteria, it switch the day with the month).

I put for criteria 1 & 2 : Format(Extractions.LDDate1.Date,
"dd/mmm/yyyy" in order to avoid the switching in between the month and
the day (which happens with your solution).

I really don't understand why each time i run this VB, i still have to
go in the sheet and the personnalised filter to click OK!!! Very weird.

Otherwise, would you have an other idea of encoding a little something
that would filter that sheet in between 2 asked dates?

Thanks a lot

Angélique

Tom Ogilvy wrote:
Selection.AutoFilter Field:=9, Criteria1:="=" &
cdate(Extractions.LDDate1.Date), Operator:=xlAnd,
Criteria2:="<=" & cDate(Extractions.LDDate2.Date)

would be a guess
--
Regards,
Tom Ogilvy






All times are GMT +1. The time now is 06:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com