sorting cells

B

barry

Hi, I wonder if any one can help, I have a grid of dates between “Y4 and
AD19†(in a spread sheet) what I would like to do is make 12 columns headed
Jan –Dec and find all dates that are January from the grid and place them in
the column headed Jan, so if the date is in row 4 in the grid it would go in
row 4 in the column headed Jan and the same with the columns headed Feb. to
Dec.
I don’t know if this is possible, it may be a fun challenge for some one.
Thank you, Barry.
 
S

Stefi

This macro does the job, if Jan –Dec columns are columns A:L:

Sub test()
Dim datesrng As Range, dcell As Range
Set datesrng = Range("Y4:AD19")
Dim mcounter(12)
For mc = 0 To 11
mcounter(mc) = 0
Next mc
For Each dcell In datesrng
destcol = Month(dcell.Value)
mcounter(destcol - 1) = mcounter(destcol - 1) + 1
Cells(mcounter(destcol - 1), destcol).Value = dcell.Value
Next dcell
End Sub

Except:
if the date is in row 4 in the grid it would go in
row 4 in the column headed Jan

Where do you want to to place the next date in row 4 in the grid if it is
also a Jan date?

Regards,
Stefi

„barry†ezt írta:
 
B

barry

there should be only one Jan in each row , what i do is type a date into a
cell and it populates the grid in two monthly intervals so 12/1/09 would give
me 12/3/09-12/5/09 and so on, I will give your macro a go . do I stick it in
the VBA page ?

Thank you for your help. Kindest Regards,Barry.
 
S

Stefi

If you want to place a date always in the same row then use this version:
Sub test2()
Dim datesrng As Range, dcell As Range
Set datesrng = Range("Y4:AD19")
For Each dcell In datesrng
destcol = Month(dcell.Value)
Cells(dcell.Row, destcol).Value = dcell.Value
Next dcell
End Sub

To install it:
Open VBA
right click your workbook name in the Project explorer window
Insert>Module
Copy macro in the code window

Regards,
Stefi


„barry†ezt írta:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top