LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copying rows based on date

And just to add to Ron's response...

Sometimes filtering dates using code doesn't work as expected.

To the OP:
If you find that the dates aren't being found, you could try this minor change:

rng.AutoFilter Field:=1, Criteria1:="=" & Clng(DateSerial(1947, 2, 23)), _
Operator:=xlOr, Criteria2:="<=" & clng(DateSerial(1988, 5, 7))

Sometimes it helps (sometimes, it doesn't).

Ron de Bruin wrote:

Try this one

Sub Copy_With_AutoFilter1_test()
Dim WS As Worksheet
Dim WSNew As Worksheet
Dim rng As Range

Set WS = Sheets("sheet1") '<<< Change
'A1 is the top left cell of your filter range and the header of the first column
Set rng = WS.Range("A1").CurrentRegion '<<< Change

'Close AutoFilter first
WS.AutoFilterMode = False

'This example filter on the first column in the range (change the field if needed)
rng.AutoFilter Field:=1, Criteria1:="=" & DateSerial(1947, 2, 23), _
Operator:=xlOr, Criteria2:="<=" & DateSerial(1988, 5, 7) ' yyyy-mm-dd format

Set WSNew = Worksheets.Add
WS.AutoFilter.Range.Copy
With WSNew.Range("A1")
' Paste:=8 will copy the columnwidth in Excel 2000 and higher
.PasteSpecial Paste:=8
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
.Select
End With
WS.AutoFilterMode = False

End Sub

--
Regards Ron De Bruin
http://www.rondebruin.nl

"flurry" wrote in message
...

Hi Ron
thanks for this - only thing I'm not sure of is where to put the

rng.AutoFilter Field:=1, Criteria1:="=" & DateSerial(1947, 2, 23), _
Operator:=xlOr, Criteria2:="<=" & DateSerial(1988, 5, 7) ' yyyy-mm-dd
format

bit within the code.

Many thanks


--
flurry
------------------------------------------------------------------------
flurry's Profile: http://www.excelforum.com/member.php...o&userid=34303
View this thread: http://www.excelforum.com/showthread...hreadid=548113


--

Dave Peterson


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying a row based on date na Excel Worksheet Functions 2 September 10th 08 07:45 PM
Copying rows from 2 sheets to a new worksheet based on date criter Phill_Morgan Excel Discussion (Misc queries) 9 August 29th 07 08:03 AM
Copying rows to different worksheets based on a cells value DanSmoach Excel Programming 2 May 8th 06 06:32 PM
Copying whole rows based upon one criteria kirbster1973 Excel Discussion (Misc queries) 2 May 26th 05 10:00 PM
Copying rows of data based on a value in a cell. Screamerz Excel Programming 4 December 16th 04 01:40 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"