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:
EXT.1stNAMELastNameDEPT
1234PaulSmithSales
4566MeredithJonesCook
2345ShirleyGrasseSales
7624EddieColemanStock
3456JRFarthersStock

<tbody>
</tbody>

Want the end results to show:
EXT.1stNAMELastNameDEPT
1234PaulSmithSales
2345ShirleyGrasseSales
4566MeredithJonesCook
7624EddieColemanStock
3456JRFarthersStock

<tbody>
</tbody>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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