PDA

View Full Version : VBA: Go Down Page & Add Seperator Lines



brennaboy
08-06-2010, 05:20 AM
Hi,

Just wondered if someone might be help me tackle the following problem using VBA in Excel.

I have a list of data which is in date order. I want to do a macro so that will add a blank line between groups of data with different dates.

E.g.

05/08/2010
05/08/2010
06/08/2010
10/08/2010
10/08/2010
10/08/2010

The macro would then go down the list and check to see when the date differs from the previous one and then the list would become:

05/08/2010
05/08/2010

06/08/2010

10/08/2010
10/08/2010
10/08/2010

Hope that makes sense.

Any ideas?

Bren.

MSTlxtHelper
08-06-2010, 10:31 AM
I'm new here but I hope this helps:

Sub Group_ByDate()
'Groups by date in Excel 2002
r = 2 'If you start in the first row you get an error
Cells(r, 1).Select
Do Until IsEmpty(Cells(r, 1))
If Not Cells(r, 1) = Cells(r - 1, 1) Then
Cells(r, 1).EntireRow.Insert
r = r + 2 'If you increment by 1 you get in an infinite loop
Else
r = r + 1
End If
Loop
End Sub
I am always looking for better ideas though.

kalusalingam
08-10-2010, 02:31 AM
It is Working Fine.

Thanks for your VBA Program
Regards,
A.kalusalingam

MSTlxtHelper
08-10-2010, 04:42 AM
no problem