PIVOT TABLE or GROUPING (Not sure what to do)

posh57

New Member
Joined
Sep 2, 2018
Messages
1
I've created a company phone directory that is currently sorted by extensions.
I'm trying to create a macro that sorted by their department.

For example:
[TABLE="width: 500"]
<tbody>[TR]
[TD]EXT.[/TD]
[TD]1stNAME[/TD]
[TD]LastName[/TD]
[TD]DEPT[/TD]
[/TR]
[TR]
[TD]1234[/TD]
[TD]Paul[/TD]
[TD]Smith[/TD]
[TD]Sales[/TD]
[/TR]
[TR]
[TD]4566[/TD]
[TD]Meredith[/TD]
[TD]Jones[/TD]
[TD]Cook[/TD]
[/TR]
[TR]
[TD]2345[/TD]
[TD]Shirley[/TD]
[TD]Grasse[/TD]
[TD]Sales[/TD]
[/TR]
[TR]
[TD]7624[/TD]
[TD]Eddie[/TD]
[TD]Coleman[/TD]
[TD]Stock[/TD]
[/TR]
[TR]
[TD]3456[/TD]
[TD]JR[/TD]
[TD]Farthers[/TD]
[TD]Stock[/TD]
[/TR]
</tbody>[/TABLE]

Want the end results to show:
[TABLE="width: 500"]
<tbody>[TR]
[TD]EXT.[/TD]
[TD]1stNAME[/TD]
[TD]LastName[/TD]
[TD]DEPT[/TD]
[/TR]
[TR]
[TD]1234[/TD]
[TD]Paul[/TD]
[TD]Smith[/TD]
[TD]Sales[/TD]
[/TR]
[TR]
[TD]2345[/TD]
[TD]Shirley[/TD]
[TD]Grasse[/TD]
[TD]Sales[/TD]
[/TR]
[TR]
[TD]4566[/TD]
[TD]Meredith[/TD]
[TD]Jones[/TD]
[TD]Cook[/TD]
[/TR]
[TR]
[TD]7624[/TD]
[TD]Eddie[/TD]
[TD]Coleman[/TD]
[TD]Stock[/TD]
[/TR]
[TR]
[TD]3456[/TD]
[TD]JR[/TD]
[TD]Farthers[/TD]
[TD]Stock[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Welcome to the MrExcel board!

I'm not sure whether I am understanding as the first table does not appear to be sorted by extension as you describe, and the second table does not appear to be sorted (alphabetically) by department.

However, assuming the original data is in columns A:D, you could try this in a copy of your workbook.

Code:
Sub SortByDept()
  Range("A1", Range("D" & Rows.Count).End(xlUp)).Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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