Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Excel 2007/2010 I'm trying to use the autofilter on a range using the actual date as a criteria. I have following code but it fails on the indicated code line. once i can autofilter for the actual date, then i need to select the apropriate data from columns B:D (visible rows) to send them to a recipient with mail. For sending mail, i'll visit the site of Ron De Bruin. I expect that RngToFilter is a valid range, so hoping i can address this imediately in the code as follow: RngToFilter.AutoFilter Field:=1, Operator:=xlFilterValues, Criteria2:=Array(2, strToday)'<<<<<< error 1004 Method Autofilter from Class Range fails but it fails. Any idea what i'm doing wrong? Sub FilterByToday() ' Dim w As Worksheet Dim RngToFilter As Range Dim strToday As String 'get actual date strToday = Date Set w = Worksheets("Sheet1") With w 'reset the autofilter mode .AutoFilterMode = False 'set range to filter to the current region without the headers Set RngToFilter = .Cells.CurrentRegion RngToFilter.Offset(1, 0).Resize(RngToFilter.Rows.Count - 1, RngToFilter.Columns.Count).Select Set RngToFilter = Selection 'use this range to filter on the actual date RngToFilter.AutoFilter Field:=1, Operator:=xlFilterValues, Criteria2:=Array(2, strToday)'<<<<<< error 1004 Method Autofilter from Class Range fails End With 'reset the autofilter mode w.AutoFilterMode = False 'clean up Set RngToFilter = Nothing Set w = Nothing End Sub here's my test data: Date article # serialnumber Description 27/07/2012 1 a aaaaaa 27/07/2012 2 b aaaaaa 27/07/2012 3 c ssssss 27/07/2012 4 d ddddd 27/07/2012 5 e cdccccc 27/07/2012 6 f xvbvfb 28/07/2012 1 a qdffg 28/07/2012 2 b svght 28/07/2012 3 c scdbf 28/07/2012 4 d ggjku 28/07/2012 5 e fgrrjk 28/07/2012 6 f xcvbfbn 28/07/2012 7 g adgvfhgj Any help welcome, Regards, Ludo |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
AutoFilter Problem | Excel Discussion (Misc queries) | |||
autofilter problem | Excel Programming | |||
PROBLEM WITH AUTOFILTER | New Users to Excel | |||
autofilter problem | Excel Worksheet Functions | |||
AutoFilter Problem | Excel Programming |