Help with this custom sort and insert blank rows macro?

Coyotex3

Well-known Member
Joined
Dec 12, 2021
Messages
507
Office Version
  1. 365
Platform
  1. Windows
Hello, so I will have a variable range like this
Automation(19128).xlsx
ABCDEFGHIJ
1Report
2User
3Date:12/01
4Time: 12:45
5
6OrderNameDescriptionCityDateInfoOrder #1Other Info
715JackNonebrookyn9/21/2020Non-Available5850.001256987569
810JohnNonebronx10/10/2020Non-Available1500.00789546521
915JackNonebronx9/21/2020Non-Available3850.001256987569
1015JackNonebronx9/21/2020Non-Available6850.001256987569
1111JaneNonebrooklyn9/10/2020Non-Available2750.00654789546
1215JackNonequeens9/21/2020Non-Available4850.001256987569
13
Sheet1


And I will use these codes

VBA Code:
Sub CopySort()
Range("A6").CurrentRegion.Sort Range("D6"), xlAscending, Range("A6"), , xlAscending, Header:=x
Const DataCol As String = "D"
    Const StartRow = 6
    LastRow = Cells(Rows.Count, DataCol).End(xlUp).Row
    Application.ScreenUpdating = False
    For x = LastRow To StartRow + 1 Step -1
        If Cells(x, DataCol).Value <> Cells(x - 1, DataCol) Then Range(DataCol & x & ":" & DataCol & x + 2).EntireRow.Insert
    Next
End Sub
To get this

Automation(19128).xlsx
ABCDEFGHI
1Report
2User
3Date:12/01
4Time: 12:45
5
6OrderNameDescriptionCityDateInfoOrder #1Other Info
7
8
9
1010JohnNonebronx10/10/2020Non-Available1500.00789546521
1115JackNonebronx9/21/2020Non-Available3850.001256987569
1215JackNonebronx9/21/2020Non-Available6850.001256987569
13
14
15
1611JaneNonebrooklyn9/10/2020Non-Available2750.00654789546
17
18
19
2015JackNonebrookyn9/21/2020Non-Available5850.001256987569
21
22
23
2415JackNonequeens9/21/2020Non-Available4850.001256987569
25
Sheet1


On some of my ranges column D will not be an exact match and will be something like: Bronx01, Bronx02 or Bronx04 etc. I would like for the code to keep them together and not separate them and hopefully get something like this

Automation(19128).xlsx
ABCDEFGHI
1Report
2User
3Date:12/01
4Time: 12:45
5
6OrderNameDescriptionCityDateInfoOrder #1Other Info
7
8
9
1010JohnNonebronx0110/10/2020Non-Available1500.00789546521
1115JackNonebronx029/21/2020Non-Available3850.001256987569
1215JackNonebronx129/21/2020Non-Available6850.001256987569
13
14
15
1611JaneNonebrooklyn9/10/2020Non-Available2750.00654789546
17
18
19
2015JackNonebrookyn9/21/2020Non-Available5850.001256987569
21
22
23
2415JackNonequeens9/21/2020Non-Available4850.001256987569
25
Sheet1


And not this which is what I get when I run the code
Automation(19128).xlsx
ABCDEFGHI
1Report
2User
3Date:12/01
4Time: 12:45
5
6OrderNameDescriptionCityDateInfoOrder #1Other Info
7
8
9
1010JohnNonebronx0110/10/2020Non-Available1500.00789546521
11
12
13
1415JackNonebronx029/21/2020Non-Available3850.001256987569
15
16
17
1815JackNonebronx129/21/2020Non-Available6850.001256987569
19
20
21
2211JaneNonebrooklyn9/10/2020Non-Available2750.00654789546
23
24
25
2615JackNonebrookyn9/21/2020Non-Available5850.001256987569
27
28
29
3015JackNonequeens9/21/2020Non-Available4850.001256987569
Sheet1
 
Thanks for the feedback - and interesting question. I just tested it with a couple of dummy entries like you suggested & yes, it works!
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

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