View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
joel joel is offline
external usenet poster
 
Posts: 9,101
Default sorting dates in another sheet

I wrote 2 macros. One to create the worksheets. the 2nd to put data into
the worksheets.

Sub createsheets()

StartYear = InputBox("Enter start year : ")
EndYear = InputBox("Enter end year : ")
For MyYears = StartYear To EndYear
Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = MyYears
For MyMonth = 1 To 12
Cells(1, MyMonth + 1) = MonthName(MyMonth)
Next MyMonth
Next MyYears

End Sub

Sub MoveDates()

With Sheets("Sheet1")
RowCount = 1
Do While .Range("A" & RowCount) < ""
Employee = .Range("A" & RowCount)
ColCount = 2
Do While .Cells(RowCount, ColCount) < ""
MyDate = .Cells(RowCount, ColCount)
MyYear = Year(MyDate)
MyMonth = Month(MyDate)
With Sheets(CStr(MyYear))
'check if employee already exists
Set c = .Columns("A").Find(what:=Employee, _
LookIn:=xlValues, lookat:=xlWhole)
If c Is Nothing Then
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
.Cells(NewRow, MyMonth + 1) = MyDate
.Cells(NewRow, MyMonth + 1).NumberFormat = _
"DD MMMM YYYY"
Else
.Cells(c.Row, MyMonth + 1) = MyDate
.Cells(c.Row, MyMonth + 1).NumberFormat = _
"DD MMMM YYYY"
End If
End With
ColCount = ColCount + 1
Loop
RowCount = RowCount + 1
Loop
End With

End Sub


"Barry" wrote:

Yes I thought it did but the columns are still mixed up which ever way I
tried it, either sort by row or column, it still did not put all Januray in
the first column and all the febuary in thr next and so on.

"Joel" wrote:

It looks like Gord answer your question in another posting.

"Barry" wrote:

19 June 2008 14 August 2008 09 October 2008 04 December 2008
13 July 2008 07 September 2008 02 November 2008 28 December
13 December 2007 07 February 2008 03 April 2008 29 May2008
This is how the dates comes in, this is three rows , I would like to copy and
sort in another sheet, so all the junes from the three rows are in one
column, so if it is column b then b1 would have any june dates from the first
row, b2 would have any june dates from the second row and so on.


"Joel" wrote:

You'll need a macro. it is pretty easy to write one but I would like you to
post some sample row of the data. Your explanation doesn't clearly specify
everything I would need to write the macro.

"Barry" wrote:

Hi, I wonder if any one can help I have a sheet that has rows of dates in
that look like this
31 October 2009 26 December 2009 20 February 2010
There are several rows and they are all have a persons name in the first
cell A1 and a start date in the next A2, the other rows are populated with
dates in two monthly intervals now because the start dates are all different
they are really hard to read each month, What I would like to do is open a
new sheet ( call it dates in order) and have 13 columns first one with a list
of names and then the next 12 the months of the year, then I would like to
transfer all the dates for January 2009 from the first sheet into the column
headed January against the original name that is was linked to in the first
sheet and so on, I would then make another sheet for 2010. I hope this makes
sense, Can it be done?

Thanks in advance , Barry.