ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   sorting cells (https://www.excelbanter.com/excel-discussion-misc-queries/216133-sorting-cells.html)

barry

sorting cells
 
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 dont know if this is possible, it may be a fun challenge for some one.
Thank you, Barry.


Stefi

sorting cells
 
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:

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 dont know if this is possible, it may be a fun challenge for some one.
Thank you, Barry.


barry

sorting cells
 
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.

"barry" wrote:

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 dont know if this is possible, it may be a fun challenge for some one.
Thank you, Barry.


Stefi

sorting cells
 
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
InsertModule
Copy macro in the code window

Regards,
Stefi


€žbarry€ ezt Γ*rta:

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.

"barry" wrote:

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 dont know if this is possible, it may be a fun challenge for some one.
Thank you, Barry.


barry

sorting cells
 
cheers

"barry" wrote:

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 dont know if this is possible, it may be a fun challenge for some one.
Thank you, Barry.


Stefi

sorting cells
 
You are welcome! Thanks for the feedback!
Stefi

€žbarry€ ezt Γ*rta:

cheers

"barry" wrote:

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 dont know if this is possible, it may be a fun challenge for some one.
Thank you, Barry.



All times are GMT +1. The time now is 04:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com