Need macro to group rows with duplicate data... sorting not enough

MineThatBird

New Member
Joined
Sep 9, 2013
Messages
3
Here's what I'm working with...
I have an excel spreadsheet with nearly 15,000 rows that I'm trying to sort. Each row has 68 columns, and represents a single piece of equipment that my company has shipped out to various job sites. The rows are sorted according to ship date, in descending order.

Here's where it gets tricky...
Sometimes as many as 30 separate pieces of equipment will be shipped out to a job site, but they're not all shipped on the same day. Because of that, the rows with the same value in the "Job Name" column aren't always grouped together, and instead are scattered throughout the spreadsheet.

Here's what I'm trying to accomplish...
What I need to do is group all equipment rows that belong to the same "Job Name" together. HOWEVER, I must also keep those jobs sorted according to "Ship Date". That means not just the equipment (rows) within each job, but also the jobs themselves (all job-groups sorted in descending order according to ship date of most recent shipment in that particular job) . Does anyone know how to create a macro that can do that?

Here's an example of what the spreadsheet looks like now:

{Equip Type, Job Name, Ship Date}

CHILLER.....WESTSIDE MALL.....JAN 28
AIR HND.....WESTSIDE MALL.....JAN 27
CHILLER.....ELEM SCHOOL.........JAN 26
AIR HND.....WESTSIDE MALL......JAN 25
I-PAK..........ELEM SCHOOL.........JAN 24
I-PAK..........ELEM SCHOOL.........JAN 23
AIR HND......JOE'S FACTORY.......JAN 22
AIR HND......JOE'S FACTORY.......JAN 21
AIR HND......WESTSIDE MALL..... JAN 20

Here's how I need for it to look:

CHILLER.....WESTSIDE MALL.....JAN 28
AIR HND.....WESTSIDE MALL.....JAN 27
AIR HND.....WESTSIDE MALL.....JAN 25
AIR HND.....WESTSIDE MALL.....JAN 20

CHILLER.....ELEM SCHOOL........JAN 26
I-PAK.........ELEM SCHOOL........JAN 24
I-PAK.........ELEM SCHOOL........JAN 23

AIR HND.....JOE'S FACTORY......JAN 22
AIR HND.....JOE'S FACTORY......JAN 21


Anyone know how to write a macro that will accomplish this?

It's not enough to simply sort by Job Name then by Date… because although that does group all equipment (rows) pertaining to a particular job together, the jobs themselves (imagine the group of rows with a single job name as just 1 row) no longer appear in descending order according to each job’s most recent shipment.

Please advise. Thanks!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi and welcome to Mr Excel Forum

I think you can simply

Select the range

Data > Sort
pick Job Name

add a new level
pick Ship Date (newest to oldest)

M.
 
Upvote 0
Hi and welcome to Mr Excel Forum

I think you can simply

Select the range

Data > Sort
pick Job Name

add a new level
pick Ship Date (newest to oldest)

M.

I appreciate your response, Marcelo. I know my post was lengthy... but as I explained in it, the simple solution you're suggesting will not produce the result I need.

Your solution will produce the following:

CHILLER.....ELEM SCHOOL........JAN 26
I-PAK.........ELEM SCHOOL........JAN 24
I-PAK.........ELEM SCHOOL........JAN 23

AIR HND.....JOE'S FACTORY......JAN 22
AIR HND.....JOE'S FACTORY......JAN 21

CHILLER.....WESTSIDE MALL.....JAN 28
AIR HND.....WESTSIDE MALL.....JAN 27
AIR HND.....WESTSIDE MALL.....JAN 25
AIR HND.....WESTSIDE MALL.....JAN 20

Notice that the "Job sets" are not organized according to most-recent ship date. the WESTSIDE MALL job has the most recent job, yet it appears at the bottom of the list.

Does this clarification help?
 
Upvote 0
Ok, I misunderstood your problem.

See if this helps

Add a helper column as below (column E)

[TABLE="class: grid"]
<TBODY>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]
Equip Type​
[/TD]
[TD]
Job Name​
[/TD]
[TD]
Ship Date​
[/TD]
[TD][/TD]
[TD]
Helper​
[/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]
CHILLER​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/28​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/27​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]
CHILLER​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/26​
[/TD]
[TD][/TD]
[TD]
jan/26​
[/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/25​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]
I-PAK​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/24​
[/TD]
[TD][/TD]
[TD]
jan/26​
[/TD]
[/TR]
[TR]
[TD]
7
[/TD]
[TD]
I-PAK​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/23​
[/TD]
[TD][/TD]
[TD]
jan/26​
[/TD]
[/TR]
[TR]
[TD]
8
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
JOE'S FACTORY​
[/TD]
[TD]
jan/22​
[/TD]
[TD][/TD]
[TD]
jan/22​
[/TD]
[/TR]
[TR]
[TD]
9
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
JOE'S FACTORY​
[/TD]
[TD]
jan/21​
[/TD]
[TD][/TD]
[TD]
jan/22​
[/TD]
[/TR]
[TR]
[TD]
10
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/20​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
</TBODY>[/TABLE]


Formula in E2 copied down
=MAX(INDEX(($B$2:$B$10=B2)*$C$2:$C$10,0))

Then select A1:E10
Data > Sort
pick Helper (newest to oldest)

getting this

[TABLE="class: grid"]
<TBODY>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]
Equip Type​
[/TD]
[TD]
Job Name​
[/TD]
[TD]
Ship Date​
[/TD]
[TD][/TD]
[TD]
Helper​
[/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]
CHILLER​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/28​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/27​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/25​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/20​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]
CHILLER​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/26​
[/TD]
[TD][/TD]
[TD]
jan/26​
[/TD]
[/TR]
[TR]
[TD]
7
[/TD]
[TD]
I-PAK​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/24​
[/TD]
[TD][/TD]
[TD]
jan/26​
[/TD]
[/TR]
[TR]
[TD]
8
[/TD]
[TD]
I-PAK​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/23​
[/TD]
[TD][/TD]
[TD]
jan/26​
[/TD]
[/TR]
[TR]
[TD]
9
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
JOE'S FACTORY​
[/TD]
[TD]
jan/22​
[/TD]
[TD][/TD]
[TD]
jan/22​
[/TD]
[/TR]
[TR]
[TD]
10
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
JOE'S FACTORY​
[/TD]
[TD]
jan/21​
[/TD]
[TD][/TD]
[TD]
jan/22​
[/TD]
[/TR]
</TBODY>[/TABLE]


Hope this helps

M.
 
Upvote 0
Probably you can have a tie like this (see in red)


[TABLE="class: grid"]
<TBODY>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]
Equip Type​
[/TD]
[TD]
Job Name​
[/TD]
[TD]
Ship Date​
[/TD]
[TD][/TD]
[TD]
Helper​
[/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]
CHILLER​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/28​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/27​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]
CHILLER​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/28​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/25​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]
I-PAK​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/24​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
7
[/TD]
[TD]
I-PAK​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/23​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
8
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
JOE'S FACTORY​
[/TD]
[TD]
jan/22​
[/TD]
[TD][/TD]
[TD]
jan/22​
[/TD]
[/TR]
[TR]
[TD]
9
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
JOE'S FACTORY​
[/TD]
[TD]
jan/21​
[/TD]
[TD][/TD]
[TD]
jan/22​
[/TD]
[/TR]
[TR]
[TD]
10
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/20​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
</TBODY>[/TABLE]


So I think you need to add a second level: Job Name
1st level: Helper (Newest to oldest)
2nd level Job Name (AZ)


[TABLE="class: grid"]
<TBODY>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]
Equip Type​
[/TD]
[TD]
Job Name​
[/TD]
[TD]
Ship Date​
[/TD]
[TD][/TD]
[TD]
Helper​
[/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]
CHILLER​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/28​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]
I-PAK​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/24​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]
I-PAK​
[/TD]
[TD]
ELEM SCHOOL​
[/TD]
[TD]
jan/23​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]
CHILLER​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/28​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/27​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
7
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/25​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
8
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
WESTSIDE MALL​
[/TD]
[TD]
jan/20​
[/TD]
[TD][/TD]
[TD]
jan/28​
[/TD]
[/TR]
[TR]
[TD]
9
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
JOE'S FACTORY​
[/TD]
[TD]
jan/22​
[/TD]
[TD][/TD]
[TD]
jan/22​
[/TD]
[/TR]
[TR]
[TD]
10
[/TD]
[TD]
AIR HND​
[/TD]
[TD]
JOE'S FACTORY​
[/TD]
[TD]
jan/21​
[/TD]
[TD][/TD]
[TD]
jan/22​
[/TD]
[/TR]
</TBODY>[/TABLE]


M.
 
Upvote 0
Probably you can have a tie like this (see in red)


[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]
Equip Type
[/TD]
[TD]
Job Name
[/TD]
[TD]
Ship Date
[/TD]
[TD][/TD]
[TD]
Helper
[/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]
CHILLER
[/TD]
[TD]
WESTSIDE MALL
[/TD]
[TD]
jan/28
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]
AIR HND
[/TD]
[TD]
WESTSIDE MALL
[/TD]
[TD]
jan/27
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]
CHILLER
[/TD]
[TD]
ELEM SCHOOL
[/TD]
[TD]
jan/28
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]
AIR HND
[/TD]
[TD]
WESTSIDE MALL
[/TD]
[TD]
jan/25
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]
I-PAK
[/TD]
[TD]
ELEM SCHOOL
[/TD]
[TD]
jan/24
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
7
[/TD]
[TD]
I-PAK
[/TD]
[TD]
ELEM SCHOOL
[/TD]
[TD]
jan/23
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
8
[/TD]
[TD]
AIR HND
[/TD]
[TD]
JOE'S FACTORY
[/TD]
[TD]
jan/22
[/TD]
[TD][/TD]
[TD]
jan/22
[/TD]
[/TR]
[TR]
[TD]
9
[/TD]
[TD]
AIR HND
[/TD]
[TD]
JOE'S FACTORY
[/TD]
[TD]
jan/21
[/TD]
[TD][/TD]
[TD]
jan/22
[/TD]
[/TR]
[TR]
[TD]
10
[/TD]
[TD]
AIR HND
[/TD]
[TD]
WESTSIDE MALL
[/TD]
[TD]
jan/20
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
</tbody>[/TABLE]


So I think you need to add a second level: Job Name
1st level: Helper (Newest to oldest)
2nd level Job Name (AZ)


[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]
Equip Type
[/TD]
[TD]
Job Name
[/TD]
[TD]
Ship Date
[/TD]
[TD][/TD]
[TD]
Helper
[/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]
CHILLER
[/TD]
[TD]
ELEM SCHOOL
[/TD]
[TD]
jan/28
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]
I-PAK
[/TD]
[TD]
ELEM SCHOOL
[/TD]
[TD]
jan/24
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]
I-PAK
[/TD]
[TD]
ELEM SCHOOL
[/TD]
[TD]
jan/23
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]
CHILLER
[/TD]
[TD]
WESTSIDE MALL
[/TD]
[TD]
jan/28
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]
AIR HND
[/TD]
[TD]
WESTSIDE MALL
[/TD]
[TD]
jan/27
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
7
[/TD]
[TD]
AIR HND
[/TD]
[TD]
WESTSIDE MALL
[/TD]
[TD]
jan/25
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
8
[/TD]
[TD]
AIR HND
[/TD]
[TD]
WESTSIDE MALL
[/TD]
[TD]
jan/20
[/TD]
[TD][/TD]
[TD]
jan/28
[/TD]
[/TR]
[TR]
[TD]
9
[/TD]
[TD]
AIR HND
[/TD]
[TD]
JOE'S FACTORY
[/TD]
[TD]
jan/22
[/TD]
[TD][/TD]
[TD]
jan/22
[/TD]
[/TR]
[TR]
[TD]
10
[/TD]
[TD]
AIR HND
[/TD]
[TD]
JOE'S FACTORY
[/TD]
[TD]
jan/21
[/TD]
[TD][/TD]
[TD]
jan/22
[/TD]
[/TR]
</tbody>[/TABLE]


M.

That basically worked! Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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