Custom Sorting via VBA

REUBEN

Board Regular
Joined
Mar 7, 2014
Messages
113
Hi All,

I need to sort three columns on a condition that the First column 'B', is sorted in alphabetical ascending order, then column 'C' is sorted based on the texts is contains and finally column 'D' is sorted with the texts it contains.

Background on the sheet (only FYI), column 'B' is the name of customers, column 'C' is the service we provided them and column 'D' is the specific task we did for them within the respective service. And the options in column 'B' and 'D' are provided via a drop down menu. So the text phrases/options remains the same.

I am unable to script anything in VBA and I understand the above would need to be coded in to VBA.

Thank you for helping me out.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You can create a macro to do this with the macro recorder.

Turn on the recorder, select all the columns containing data, go to Data/Sort, sort by col B then by col C then by col D, turn off the recorder.
 
Upvote 0
You can create a macro to do this with the macro recorder.

Turn on the recorder, select all the columns containing data, go to Data/Sort, sort by col B then by col C then by col D, turn off the recorder.

Thank you for your quick reply.

One detail I forgot to mention was that the last row contains text that must not be changed with. And this text is auto populated everytime a user has completed one full row of data.

The Sort function must not sort this last row.

Anywya, I tried the macro recorder just now (its a great tool to automate stuff). But after I sorted the second column 'C', the data that was storted in the first column 'C', was shuffled as well.

My idea is to have data sorted primarily based on Column 'B' (name of customers), then by column 'C' (the services provided to each customer) and finally by column 'D', (individual tasks performed under each service). So the end result will be a display to see bunched entries for each customer arranged alphabetically, and the service & their corresponding tasks also sorted accordingly.

Hope this makes sense.
 
Upvote 0
Anywya, I tried the macro recorder just now (its a great tool to automate stuff). But after I sorted the second column 'C', the data that was storted in the first column 'C', was shuffled as well.

You did not sort properly.
You need to sort by three levels - select sort by col B, add level & select sort by col C, add level and sort by col D, click OK.

To set the sort range, what column can be used to find the last row?
 
Upvote 0
Does the data actually start in column A? If so, should column A be shuffled when the data is sorted on columns B:D?

Is there data beyond column D? If so, should that data also be shuffled when the data is sorted on columns B:D?
 
Upvote 0
You did not sort properly.
You need to sort by three levels - select sort by col B, add level & select sort by col C, add level and sort by col D, click OK.

To set the sort range, what column can be used to find the last row?

Tried it out again and if I just need to sort the 3 columns, then the procedure you've described works perfectly. However, that takes in the last row as well and sorts it as per alphabetical order. I need to prevent excel from doing this. As that last row contains auto-populated instructions for the user when they start adding data to the following row/s.

Any suggestions how to prevent excel from sorting the last row?
 
Upvote 0
Does the data actually start in column A? If so, should column A be shuffled when the data is sorted on columns B:D?

Is there data beyond column D? If so, should that data also be shuffled when the data is sorted on columns B:D?


Hi Peter_SSs

Good guess, but the first column is an empty one. I'm using it to add a sort of padding to the first column where the data begins (for cosmetic reasons). There is data beyond column 'D', and I believe, the above described Data Sort process (by footoo) would be taking care of this.
 
Upvote 0
Any suggestions how to prevent excel from sorting the last row?
Yes, but it depends on the answers to my previous questions. :)

Edit: OK, we posted at about the same time.
Still, can you confirm that the data beyond column D gets rearranged, along with the B:D data?
 
Last edited:
Upvote 0
Are you referring to whether the data in the following columns must be shuffled as well? Then Yes, they too must be shuffled accodingly.
 
Upvote 0
You need to answer this question :

To set the sort range, what column can be used to find the last row?
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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