Automatic Sorting and Inserting Rows

A

Andy

I need to sort dates in a single column and group them so that different
dates are separated by an inserted row. Is there a way to do this without
performing it manually? Any help would be greatly appreciated!
 
J

Joel

The macro below will work on the active sheet if the dates are in Column A

Sub InsertRows()

LastRow = Range("A" & Rows.Count).End(xlUp).Row

For RowCount = (LastRow - 1) To 1 Step -1
If Range("A" & RowCount) <> Range("A" & (RowCount + 1)) Then
Rows(RowCount + 1).Insert
End If
Next
 
F

Fred Smith

One option is to use Data>Subtotal. It will insert a line after each date
group. It has the additional benefit of summing other columns, which you may
find useful. If not, have it sum a hidden column.

Regards,
Fred.
 
A

Andy

Joel, thanks a lot! Macro works just as I wanted. However, there is an
important detail that I failed to mention. The first four rows of the data I
am working with are text titles, meaning that I would not want to separate
different rows until the fifth row down. If this macro could work for dates
only, or for all rows after the fourth, it would be perfect! Again, I truly
appreciate the help- it will make a big difference for everyone at work.

Thanks
 
F

Fred Smith

Change this line:
For RowCount = (LastRow - 1) To 1 Step -1

to
For RowCount = (LastRow - 1) To 5 Step -1

Regards,
Fred.
 

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