PC Review


Reply
Thread Tools Rate Thread

data sorting according to the date

 
 
=?Utf-8?B?bWFzc2k=?=
Guest
Posts: n/a
 
      18th Oct 2006
i have column A with the dates from 1 jan 06 to 31 dec 06 and the column next
to it has some data.
how can i do a filter that can sort the data only for the range i want (ie
from 1 jan to 22 apr 06)
thanks
 
Reply With Quote
 
 
 
 
Alan
Guest
Posts: n/a
 
      18th Oct 2006

Sub SortData()

Dim StartDate As Date
Dim EndDate As Date
Dim StartRow As Integer
Dim EndRow As Integer
Dim i As Integer

' Allocate cells in which you can specify the
' StartDate and EndDate for your filter (Assumed D1 and D2 here)
' Enter dates into your chosen cells formatted as dates.

StartDate = Range("D1").Value
EndDate = Range("D2").Value

Range("A1").Select
' Find the StartDate position
Do Until ActiveCell.Offset(i, 0).Value = StartDate
i = i + 1
Loop

StartRow = Range("A1").Offset(i, 0).Row

' Reset the counter
i=0
' Find the EndDate position
Do Until ActiveCell.Offset(i, 0).Value = EndDate
i = i + 1
Loop

EndRow = Range("A1").Offset(i, 0).Row

' Now use StartRow and EndRow to sort your data

End Sub

massi wrote:
> i have column A with the dates from 1 jan 06 to 31 dec 06 and the column next
> to it has some data.
> how can i do a filter that can sort the data only for the range i want (ie
> from 1 jan to 22 apr 06)
> thanks


 
Reply With Quote
 
=?Utf-8?B?bWFzc2k=?=
Guest
Posts: n/a
 
      18th Oct 2006
sorry but i cannot figure out how it works.
if i try to run the macro as normal nothing happens...

"Alan" wrote:

>
> Sub SortData()
>
> Dim StartDate As Date
> Dim EndDate As Date
> Dim StartRow As Integer
> Dim EndRow As Integer
> Dim i As Integer
>
> ' Allocate cells in which you can specify the
> ' StartDate and EndDate for your filter (Assumed D1 and D2 here)
> ' Enter dates into your chosen cells formatted as dates.
>
> StartDate = Range("D1").Value
> EndDate = Range("D2").Value
>
> Range("A1").Select
> ' Find the StartDate position
> Do Until ActiveCell.Offset(i, 0).Value = StartDate
> i = i + 1
> Loop
>
> StartRow = Range("A1").Offset(i, 0).Row
>
> ' Reset the counter
> i=0
> ' Find the EndDate position
> Do Until ActiveCell.Offset(i, 0).Value = EndDate
> i = i + 1
> Loop
>
> EndRow = Range("A1").Offset(i, 0).Row
>
> ' Now use StartRow and EndRow to sort your data
>
> End Sub
>
> massi wrote:
> > i have column A with the dates from 1 jan 06 to 31 dec 06 and the column next
> > to it has some data.
> > how can i do a filter that can sort the data only for the range i want (ie
> > from 1 jan to 22 apr 06)
> > thanks

>
>

 
Reply With Quote
 
Alan
Guest
Posts: n/a
 
      18th Oct 2006
Massi,

The macro simply looks up the positions of the start row for your sort
and the end row. As it stands it will appear to do nothing but if you
insert a temporary line into the code

msgbox "Start Row = " & StartRow & vbcr & "End Row = " & EndRow

you will be able to see what is happening.

(Insert new code below the line that says "Now use StartRow and EndRow
to sort your data" you will see what it has calculated)

You can now use the start and end references to direct your sort.

Alan

massi wrote:
> sorry but i cannot figure out how it works.
> if i try to run the macro as normal nothing happens...
>
> "Alan" wrote:
>
> >
> > Sub SortData()
> >
> > Dim StartDate As Date
> > Dim EndDate As Date
> > Dim StartRow As Integer
> > Dim EndRow As Integer
> > Dim i As Integer
> >
> > ' Allocate cells in which you can specify the
> > ' StartDate and EndDate for your filter (Assumed D1 and D2 here)
> > ' Enter dates into your chosen cells formatted as dates.
> >
> > StartDate = Range("D1").Value
> > EndDate = Range("D2").Value
> >
> > Range("A1").Select
> > ' Find the StartDate position
> > Do Until ActiveCell.Offset(i, 0).Value = StartDate
> > i = i + 1
> > Loop
> >
> > StartRow = Range("A1").Offset(i, 0).Row
> >
> > ' Reset the counter
> > i=0
> > ' Find the EndDate position
> > Do Until ActiveCell.Offset(i, 0).Value = EndDate
> > i = i + 1
> > Loop
> >
> > EndRow = Range("A1").Offset(i, 0).Row
> >
> > ' Now use StartRow and EndRow to sort your data
> >
> > End Sub
> >
> > massi wrote:
> > > i have column A with the dates from 1 jan 06 to 31 dec 06 and the column next
> > > to it has some data.
> > > how can i do a filter that can sort the data only for the range i want (ie
> > > from 1 jan to 22 apr 06)
> > > thanks

> >
> >


 
Reply With Quote
 
=?Utf-8?B?bWFzc2k=?=
Guest
Posts: n/a
 
      18th Oct 2006
Hi Alan,
I have tried to put this after the code you gave me but it doesn't work. I
have also tried to put
StartDate instead StartRow but the result is the same...

Rows("StartRow:EndRow").Select
Selection.Copy
Sheets("Sheet3").Select
Sheets.Add
ActiveSheet.Paste

"Alan" wrote:

> Massi,
>
> The macro simply looks up the positions of the start row for your sort
> and the end row. As it stands it will appear to do nothing but if you
> insert a temporary line into the code
>
> msgbox "Start Row = " & StartRow & vbcr & "End Row = " & EndRow
>
> you will be able to see what is happening.
>
> (Insert new code below the line that says "Now use StartRow and EndRow
> to sort your data" you will see what it has calculated)
>
> You can now use the start and end references to direct your sort.
>
> Alan
>
> massi wrote:
> > sorry but i cannot figure out how it works.
> > if i try to run the macro as normal nothing happens...
> >
> > "Alan" wrote:
> >
> > >
> > > Sub SortData()
> > >
> > > Dim StartDate As Date
> > > Dim EndDate As Date
> > > Dim StartRow As Integer
> > > Dim EndRow As Integer
> > > Dim i As Integer
> > >
> > > ' Allocate cells in which you can specify the
> > > ' StartDate and EndDate for your filter (Assumed D1 and D2 here)
> > > ' Enter dates into your chosen cells formatted as dates.
> > >
> > > StartDate = Range("D1").Value
> > > EndDate = Range("D2").Value
> > >
> > > Range("A1").Select
> > > ' Find the StartDate position
> > > Do Until ActiveCell.Offset(i, 0).Value = StartDate
> > > i = i + 1
> > > Loop
> > >
> > > StartRow = Range("A1").Offset(i, 0).Row
> > >
> > > ' Reset the counter
> > > i=0
> > > ' Find the EndDate position
> > > Do Until ActiveCell.Offset(i, 0).Value = EndDate
> > > i = i + 1
> > > Loop
> > >
> > > EndRow = Range("A1").Offset(i, 0).Row
> > >
> > > ' Now use StartRow and EndRow to sort your data
> > >
> > > End Sub
> > >
> > > massi wrote:
> > > > i have column A with the dates from 1 jan 06 to 31 dec 06 and the column next
> > > > to it has some data.
> > > > how can i do a filter that can sort the data only for the range i want (ie
> > > > from 1 jan to 22 apr 06)
> > > > thanks
> > >
> > >

>
>

 
Reply With Quote
 
Alan
Guest
Posts: n/a
 
      19th Oct 2006
Massi

Replace
Rows("StartRow:EndRow").Select
with
Rows(StartRow & ":" & EndRow).Select

Alan

massi wrote:
> Hi Alan,
> I have tried to put this after the code you gave me but it doesn't work. I
> have also tried to put
> StartDate instead StartRow but the result is the same...
>
> Rows("StartRow:EndRow").Select
> Selection.Copy
> Sheets("Sheet3").Select
> Sheets.Add
> ActiveSheet.Paste
>
> "Alan" wrote:
>
> > Massi,
> >
> > The macro simply looks up the positions of the start row for your sort
> > and the end row. As it stands it will appear to do nothing but if you
> > insert a temporary line into the code
> >
> > msgbox "Start Row = " & StartRow & vbcr & "End Row = " & EndRow
> >
> > you will be able to see what is happening.
> >
> > (Insert new code below the line that says "Now use StartRow and EndRow
> > to sort your data" you will see what it has calculated)
> >
> > You can now use the start and end references to direct your sort.
> >
> > Alan
> >
> > massi wrote:
> > > sorry but i cannot figure out how it works.
> > > if i try to run the macro as normal nothing happens...
> > >
> > > "Alan" wrote:
> > >
> > > >
> > > > Sub SortData()
> > > >
> > > > Dim StartDate As Date
> > > > Dim EndDate As Date
> > > > Dim StartRow As Integer
> > > > Dim EndRow As Integer
> > > > Dim i As Integer
> > > >
> > > > ' Allocate cells in which you can specify the
> > > > ' StartDate and EndDate for your filter (Assumed D1 and D2 here)
> > > > ' Enter dates into your chosen cells formatted as dates.
> > > >
> > > > StartDate = Range("D1").Value
> > > > EndDate = Range("D2").Value
> > > >
> > > > Range("A1").Select
> > > > ' Find the StartDate position
> > > > Do Until ActiveCell.Offset(i, 0).Value = StartDate
> > > > i = i + 1
> > > > Loop
> > > >
> > > > StartRow = Range("A1").Offset(i, 0).Row
> > > >
> > > > ' Reset the counter
> > > > i=0
> > > > ' Find the EndDate position
> > > > Do Until ActiveCell.Offset(i, 0).Value = EndDate
> > > > i = i + 1
> > > > Loop
> > > >
> > > > EndRow = Range("A1").Offset(i, 0).Row
> > > >
> > > > ' Now use StartRow and EndRow to sort your data
> > > >
> > > > End Sub
> > > >
> > > > massi wrote:
> > > > > i have column A with the dates from 1 jan 06 to 31 dec 06 and the column next
> > > > > to it has some data.
> > > > > how can i do a filter that can sort the data only for the range i want (ie
> > > > > from 1 jan to 22 apr 06)
> > > > > thanks
> > > >
> > > >

> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting CSV Data By Date caveman.savant Microsoft Excel Programming 8 12th Sep 2008 04:23 PM
Sorting data by Date Mark F. Microsoft Excel Worksheet Functions 1 11th Nov 2005 08:17 PM
sorting data by date =?Utf-8?B?S2F0aGVyaW5l?= Microsoft Excel Worksheet Functions 1 17th Jun 2005 03:12 PM
Sorting data by date =?Utf-8?B?S2F0aGVyaW5l?= Microsoft Excel Worksheet Functions 2 14th Jun 2005 02:37 PM
Sorting out data by date rutima - ExcelForums.com Microsoft Excel Discussion 1 24th Sep 2004 12:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:24 AM.