Hello, so I will have a variable range like this
And I will use these codes
To get this
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
And not this which is what I get when I run the code
Automation(19128).xlsx | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | |||
1 | Report | |||||||||||
2 | User | |||||||||||
3 | Date:12/01 | |||||||||||
4 | Time: 12:45 | |||||||||||
5 | ||||||||||||
6 | Order | Name | Description | City | Date | Info | Order # | 1 | Other Info | |||
7 | 15 | Jack | None | brookyn | 9/21/2020 | Non-Available | 5 | 850.00 | 1256987569 | |||
8 | 10 | John | None | bronx | 10/10/2020 | Non-Available | 1 | 500.00 | 789546521 | |||
9 | 15 | Jack | None | bronx | 9/21/2020 | Non-Available | 3 | 850.00 | 1256987569 | |||
10 | 15 | Jack | None | bronx | 9/21/2020 | Non-Available | 6 | 850.00 | 1256987569 | |||
11 | 11 | Jane | None | brooklyn | 9/10/2020 | Non-Available | 2 | 750.00 | 654789546 | |||
12 | 15 | Jack | None | queens | 9/21/2020 | Non-Available | 4 | 850.00 | 1256987569 | |||
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
Automation(19128).xlsx | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
1 | Report | ||||||||||
2 | User | ||||||||||
3 | Date:12/01 | ||||||||||
4 | Time: 12:45 | ||||||||||
5 | |||||||||||
6 | Order | Name | Description | City | Date | Info | Order # | 1 | Other Info | ||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | 10 | John | None | bronx | 10/10/2020 | Non-Available | 1 | 500.00 | 789546521 | ||
11 | 15 | Jack | None | bronx | 9/21/2020 | Non-Available | 3 | 850.00 | 1256987569 | ||
12 | 15 | Jack | None | bronx | 9/21/2020 | Non-Available | 6 | 850.00 | 1256987569 | ||
13 | |||||||||||
14 | |||||||||||
15 | |||||||||||
16 | 11 | Jane | None | brooklyn | 9/10/2020 | Non-Available | 2 | 750.00 | 654789546 | ||
17 | |||||||||||
18 | |||||||||||
19 | |||||||||||
20 | 15 | Jack | None | brookyn | 9/21/2020 | Non-Available | 5 | 850.00 | 1256987569 | ||
21 | |||||||||||
22 | |||||||||||
23 | |||||||||||
24 | 15 | Jack | None | queens | 9/21/2020 | Non-Available | 4 | 850.00 | 1256987569 | ||
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
1 | Report | ||||||||||
2 | User | ||||||||||
3 | Date:12/01 | ||||||||||
4 | Time: 12:45 | ||||||||||
5 | |||||||||||
6 | Order | Name | Description | City | Date | Info | Order # | 1 | Other Info | ||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | 10 | John | None | bronx01 | 10/10/2020 | Non-Available | 1 | 500.00 | 789546521 | ||
11 | 15 | Jack | None | bronx02 | 9/21/2020 | Non-Available | 3 | 850.00 | 1256987569 | ||
12 | 15 | Jack | None | bronx12 | 9/21/2020 | Non-Available | 6 | 850.00 | 1256987569 | ||
13 | |||||||||||
14 | |||||||||||
15 | |||||||||||
16 | 11 | Jane | None | brooklyn | 9/10/2020 | Non-Available | 2 | 750.00 | 654789546 | ||
17 | |||||||||||
18 | |||||||||||
19 | |||||||||||
20 | 15 | Jack | None | brookyn | 9/21/2020 | Non-Available | 5 | 850.00 | 1256987569 | ||
21 | |||||||||||
22 | |||||||||||
23 | |||||||||||
24 | 15 | Jack | None | queens | 9/21/2020 | Non-Available | 4 | 850.00 | 1256987569 | ||
25 | |||||||||||
Sheet1 |
And not this which is what I get when I run the code
Automation(19128).xlsx | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
1 | Report | ||||||||||
2 | User | ||||||||||
3 | Date:12/01 | ||||||||||
4 | Time: 12:45 | ||||||||||
5 | |||||||||||
6 | Order | Name | Description | City | Date | Info | Order # | 1 | Other Info | ||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | 10 | John | None | bronx01 | 10/10/2020 | Non-Available | 1 | 500.00 | 789546521 | ||
11 | |||||||||||
12 | |||||||||||
13 | |||||||||||
14 | 15 | Jack | None | bronx02 | 9/21/2020 | Non-Available | 3 | 850.00 | 1256987569 | ||
15 | |||||||||||
16 | |||||||||||
17 | |||||||||||
18 | 15 | Jack | None | bronx12 | 9/21/2020 | Non-Available | 6 | 850.00 | 1256987569 | ||
19 | |||||||||||
20 | |||||||||||
21 | |||||||||||
22 | 11 | Jane | None | brooklyn | 9/10/2020 | Non-Available | 2 | 750.00 | 654789546 | ||
23 | |||||||||||
24 | |||||||||||
25 | |||||||||||
26 | 15 | Jack | None | brookyn | 9/21/2020 | Non-Available | 5 | 850.00 | 1256987569 | ||
27 | |||||||||||
28 | |||||||||||
29 | |||||||||||
30 | 15 | Jack | None | queens | 9/21/2020 | Non-Available | 4 | 850.00 | 1256987569 | ||
Sheet1 |