ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Automatic Sorting and Inserting Rows (https://www.excelbanter.com/excel-discussion-misc-queries/190353-automatic-sorting-inserting-rows.html)

Andy

Automatic Sorting and Inserting Rows
 
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!


joel

Automatic Sorting and Inserting Rows
 
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

"Andy" wrote:

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!


Fred Smith[_4_]

Automatic Sorting and Inserting Rows
 
One option is to use DataSubtotal. 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.

"Andy" wrote in message
...
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!



Andy

Automatic Sorting and Inserting Rows
 
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

"Joel" wrote:

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

"Andy" wrote:

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!


Fred Smith[_4_]

Automatic Sorting and Inserting Rows
 
Change this line:
For RowCount = (LastRow - 1) To 1 Step -1

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

Regards,
Fred.

"Andy" wrote in message
...
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

"Joel" wrote:

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

"Andy" wrote:

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!




All times are GMT +1. The time now is 08:14 PM.

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