MS Excel VBA Code to Sort a Column Based on Distance and then Group Values

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
421
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for you assistance.
I have a set of data that I am trying to sort by four criteria in the following order:
(1) By distance
(2) Name
(3) Gender
(4) Yes or No

The issue is that some of the names are repeated so there is no way to group them together if one of the other columns like Distance is different. Take this small example, I would like to sort by Distance and name. Initially I have this:
Specialist Tool - (Active).xlsm
ABC
1NAMENEWDISTANCE
2Ron SmithYes2
3Jack FrostNo10
4Ron SmithYes20
Sheet2


Finally I would like this:
Specialist Tool - (Active).xlsm
ABC
1NAMENEWDISTANCE
2Ron SmithYes2
3Ron SmithYes20
4Jack FrostNo10
Sheet2


But there is no way to do this with sort because if you sort by distance, you could not group all the Ron Smith's together.

Any ideas? Please note the data size I am using is much larger (like 150+ rows)
 
You could use a helper column & sort on that 1st
Fluff.xlsm
ABCD
1NAMENEWDISTANCEhelp
2Ron SmithYes22
3Jack FrostNo1010
4Ron SmithYes202
Data
Cell Formulas
RangeFormula
D2:D4D2=MINIFS(C:C,A:A,A2)
Thanks for this @Fluff. This works. Apologies I just marked it but I thought I already had done so.
Now in regards to setting up the formula for the help column. Is there way to set ranges for each column?

Thanks!
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,214,385
Messages
6,119,208
Members
448,874
Latest member
b1step2far

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