Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting a date range of data

Hi, I hope you can help. I have a worksheet containing
columns of data. I use the following to sort column A in
date order;

Columns("A:H").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
Range("A1").Select

But what I would like to do is to display only the data in
a specified range, for example say;

startdate = "01/10/03"
enddate = "15/10/03"

Is there a way I could state a macro that would either
delete all the data outside this range leaving the data I
require, or copy the required data to another worksheet so
that I can then display it from there.

Thanks
Robert

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default Sorting a date range of data

Robert,

After you have sorted your data, you can use the autofilter to filter
your data for your criteria. The code below is based on the
assumption that your dates are in column A, and that the sheet
"Sheet2" is available for pasting the values.

Note that in VBA, dates are in American standard Month/Day/Year, not
Day/Month/Year as in your example.

HTH,
Bernie
MS Excel MVP

Sub Macro1()
Dim StartDate As Date
Dim EndDate As Date
StartDate = DateValue("10/01/03")
EndDate = DateValue("10/15/03")

With Range("A:H")
.AutoFilter _
Field:=1, _
Criteria1:="=" & StartDate, _
Operator:=xlAnd, _
Criteria2:="<=" & EndDate
.SpecialCells(xlCellTypeVisible).Copy _
Worksheets("Sheet2").Range("A1")
.AutoFilter
End With

End Sub


"Robert" wrote in message
...
Hi, I hope you can help. I have a worksheet containing
columns of data. I use the following to sort column A in
date order;

Columns("A:H").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
Range("A1").Select

But what I would like to do is to display only the data in
a specified range, for example say;

startdate = "01/10/03"
enddate = "15/10/03"

Is there a way I could state a macro that would either
delete all the data outside this range leaving the data I
require, or copy the required data to another worksheet so
that I can then display it from there.

Thanks
Robert



Reply
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
sorting data from one table/range to another table/range Danko Jotanovic Excel Discussion (Misc queries) 1 April 15th 09 01:06 PM
Problem with Range and Sorting Data Elise148 Excel Discussion (Misc queries) 0 July 5th 07 03:40 PM
Sorting data by Date Mark F. Excel Worksheet Functions 1 November 11th 05 08:17 PM
sorting data by date Katherine Excel Worksheet Functions 1 June 17th 05 03:12 PM
Sorting data by date Katherine Excel Worksheet Functions 2 June 14th 05 02:37 PM


All times are GMT +1. The time now is 11:07 AM.

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

About Us

"It's about Microsoft Excel"