ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add rows between months (https://www.excelbanter.com/excel-programming/367347-add-rows-between-months.html)

Josh[_15_]

Add rows between months
 
Hello all.

I have 10 years worth of data that I would like to separate by month.
As of now there is no separation between, for example, January and
February of 2000. An example is this:

01/04/2000
01/10/2000
01/26/2000
02/05/2000
02/17/2000

I would like a macro that would automatically insert three rows between
each month. This is tricky because there are a differing number of
entries for each month. January might have three, while February has
2, etc. I would like this to be applied to the entire 10 year period.

Any help is appreciated. Thanks.


NickHK

Add rows between months
 
Josh,
Does Excel's dataSubTotal achieve your goal ?
You may need to add a helper column, Month(<DateColumn).

NickHK

"Josh" wrote in message
ups.com...
Hello all.

I have 10 years worth of data that I would like to separate by month.
As of now there is no separation between, for example, January and
February of 2000. An example is this:

01/04/2000
01/10/2000
01/26/2000
02/05/2000
02/17/2000

I would like a macro that would automatically insert three rows between
each month. This is tricky because there are a differing number of
entries for each month. January might have three, while February has
2, etc. I would like this to be applied to the entire 10 year period.

Any help is appreciated. Thanks.




Die_Another_Day

Add rows between months
 
If nick's Idea doesn't work then try this:
Sub SplitMonth()
Dim Cnt As Double
Dim CurrCell As Range
Dim PrevCell As Range
Cnt = 1 'Change to your starting row
Set PrevCell = Range("A1") 'Change to your starting cell
Do
Set CurrCell = PrevCell.Offset(1,0)
If Evaluate(Month(PrevCell) < Month(CurrCell)) Then
Range(CurrCell, CurrCell.Offset(2, 0)).EntireRow.Insert xlDown
Cnt = Cnt + 3
Else
Cnt = Cnt + 1
End If
Set PrevCell = CurrCell
Loop While CurrCell < ""
End Sub

HTH

Die_Another_Day

NickHK wrote:
Josh,
Does Excel's dataSubTotal achieve your goal ?
You may need to add a helper column, Month(<DateColumn).

NickHK

"Josh" wrote in message
ups.com...
Hello all.

I have 10 years worth of data that I would like to separate by month.
As of now there is no separation between, for example, January and
February of 2000. An example is this:

01/04/2000
01/10/2000
01/26/2000
02/05/2000
02/17/2000

I would like a macro that would automatically insert three rows between
each month. This is tricky because there are a differing number of
entries for each month. January might have three, while February has
2, etc. I would like this to be applied to the entire 10 year period.

Any help is appreciated. Thanks.




All times are GMT +1. The time now is 02:46 PM.

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