Sort Columns - first A, then B, then C

adarron

New Member
Joined
Oct 26, 2012
Messages
4
Hello, I'm having a bit of trouble creating a macro that will sort columns in order - I've created a form that allows people to select a broad catagory ie) Schools, then a sub catagory ie) Primary or Seconary, and type in a third ie) Projects or Teachers

I'm trying to write a macro so that once they enter the form, their chocies will be automatically sorted alphabetically, first by column A, then B, then C - to look like:

Schools - Primary - Projects - A
Schools - Primary - Projects - B
Schools - Primary - Projects - C
Schools - Primary - Teachers - B
Schools - Secondary - Projects - C
Schools - Secondary - Teachers - A
Schools - Secondary - Teachers - B
Schools - Secondary - Teachers - C


However I'm having the issue where if column B or C are left blank - the columns are not sorted properly, and the catagories in column A get separated out.. if that makes any sense?

My code at the moment looks like:

Range("A1").Select


ActiveSheet.Unprotect
Range("A1").Sort Key1:=Range("A2:A3"), Order1:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Range("B2").Sort Key1:=Range("B2:B3"), Order2:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Range("C3").Sort Key1:=Range("C3"), Order3:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

But I'm very new to this so not sure where I'm going wrong!
Thank you very much for any advice :)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I think you may be doing three separate sorts into of a single sort. You can sort all three at the same time.
If you turn on your Macro Recorder, and record yourself doing a single sort on three levels, it should work.

If you cannot get it to work properly, please post the data from an example that does not work (original data and expected results).
Also please let us know which version of Excel you are using.
 
Upvote 0

Forum statistics

Threads
1,216,169
Messages
6,129,270
Members
449,497
Latest member
The Wamp

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