ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro with custom autofilter for greater and less than specific da (https://www.excelbanter.com/excel-discussion-misc-queries/120833-macro-custom-autofilter-greater-less-than-specific-da.html)

Peter-Jon

Macro with custom autofilter for greater and less than specific da
 
Hi

I am trying to record a macro where I autofilter a column containing dates.
I need to apply greater than and less than to get a specific month eg.
greater than 11/01/06 and less than 11/30/06 to get the info for the month of
november. When I record the macro and run it I find that there is no data
displayed yet when I autofilter without the help of a macro then the
information is there. Anyone have any ideas what I'm doing wrong?

Dave Peterson

Macro with custom autofilter for greater and less than specific da
 
I'm not sure how you're getting the date, but sometimes making sure it's a Long
will help:

.Range("a1").CurrentRegion.AutoFilter Field:=3, _
Criteria1:="=" & CLng(CDate(UserVal))

Sometimes using the same numberformat helps:

.Range("a1").CurrentRegion.AutoFilter Field:=3, _
Criteria1:="=" & Format(CDate(UserVal),"mm/dd/yyyy")

(try it for both dates)



Peter-Jon wrote:

Hi

I am trying to record a macro where I autofilter a column containing dates.
I need to apply greater than and less than to get a specific month eg.
greater than 11/01/06 and less than 11/30/06 to get the info for the month of
november. When I record the macro and run it I find that there is no data
displayed yet when I autofilter without the help of a macro then the
information is there. Anyone have any ideas what I'm doing wrong?


--

Dave Peterson


All times are GMT +1. The time now is 10:37 PM.

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