DPChristman
Board Regular
- Joined
- Sep 4, 2012
- Messages
- 172
- Office Version
- 365
- Platform
- Windows
I was given this macro by user JoeMo, and it proved very helpful at automatically putting three empty rows between groups of data in a large spreadsheet.
However, I now have a problem where the macro re-sorts the data by district only (column B), rather than first by zone (column A), then district, and then store (column C)
Since the district numbers do not always fall into the logical zones.
Example: district 101 is in zone 10, but district 133 is also in zone 10, and not in Zone 13, which is where it would logically fall.
As a result, doing summaries by District and Zone is difficult to do, and follow.
The original thread can be found at http://www.mrexcel.com/forum/excel-questions/956537-splitting-data-into-districts.html
'
' ThreeRowsBetween Macro
'
Dim i As Long
Application.ScreenUpdating = False
With Rows(7)
.Insert
.Offset(-1, 0).RowHeight = 1
End With
Range("A8").CurrentRegion.SORT key1:=[b2], order1:=xlAscending, Header:=xlYes
For i = Range("B8:B" & Cells(Rows.Count, "B").End(xlUp).Row).Rows.Count To 10 Step -1
If Cells(i, "B") <> Cells(i - 1, "B") Then
Cells(i, "B").Resize(3, 1).EntireRow.Insert
End If
Next i
Rows(7).Delete
Application.ScreenUpdating = True
End Sub
However, I now have a problem where the macro re-sorts the data by district only (column B), rather than first by zone (column A), then district, and then store (column C)
Since the district numbers do not always fall into the logical zones.
Example: district 101 is in zone 10, but district 133 is also in zone 10, and not in Zone 13, which is where it would logically fall.
As a result, doing summaries by District and Zone is difficult to do, and follow.
The original thread can be found at http://www.mrexcel.com/forum/excel-questions/956537-splitting-data-into-districts.html
'
' ThreeRowsBetween Macro
'
Dim i As Long
Application.ScreenUpdating = False
With Rows(7)
.Insert
.Offset(-1, 0).RowHeight = 1
End With
Range("A8").CurrentRegion.SORT key1:=[b2], order1:=xlAscending, Header:=xlYes
For i = Range("B8:B" & Cells(Rows.Count, "B").End(xlUp).Row).Rows.Count To 10 Step -1
If Cells(i, "B") <> Cells(i - 1, "B") Then
Cells(i, "B").Resize(3, 1).EntireRow.Insert
End If
Next i
Rows(7).Delete
Application.ScreenUpdating = True
End Sub