HELP! - Macro Sort issue

DPChristman

Board Regular
Joined
Sep 4, 2012
Messages
172
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Code:
[COLOR=#333333]Range("A8").CurrentRegion.SORT key1:=[A2], order1:=xlAscending, Header:=xlYes _
[/COLOR][COLOR=#333333]key2:=[B2], order2:=xlAscending, Header:=xlYes _
[/COLOR][COLOR=#333333]key3:=[C2], order3:=xlAscending, Header:=xlYes[/COLOR]
 
Upvote 0
Sorry, I don't understand this enough to know. What do I have to replace with that ?

Do I remove:
Range("A8").CurrentRegion.SORT key1:=[b2], order1:=xlAscending, Header:=xlYes
And replace it with:
Range("A8").CurrentRegion.SORT key1:=[A2], order1:=xlAscending, Header:=xlYes _
key2:=[B2], order2:=xlAscending, Header:=xlYes _
key3:=[C2], order3:=xlAscending, Header:=xlYes
 
Upvote 0
By the way, I cross posted this on XLguru, giving JoeMo full credit for an awesome solve.
 
Upvote 0
Sorry, I don't understand this enough to know. What do I have to replace with that ?

Do I remove:
Range("A8").CurrentRegion.SORT key1:=[b2], order1:=xlAscending, Header:=xlYes
And replace it with:
Range("A8").CurrentRegion.SORT key1:=[A2], order1:=xlAscending, Header:=xlYes _
key2:=[B2], order2:=xlAscending, Header:=xlYes _
key3:=[C2], order3:=xlAscending, Header:=xlYes
Yes. Try and see what happens.
 
Upvote 0

Forum statistics

Threads
1,217,040
Messages
6,134,146
Members
449,861
Latest member
DMJHohl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top