VBA Sort Based On Two Columns

mikemmb

Board Regular
Joined
Mar 4, 2009
Messages
59
Hi,
Can someone please help me, I am trying to write a called sub (I need a sub because I also want to do some other things) to Sort a worksheet based on the crieria in two columns.

What I have is:
(a) A column (A:A) containing a mix of up to 500 numbers (1 to 3 digit) and a few text entries (1 to 6 char). These form the basis of a movement log where say 100 different drivers (each with unique identity) are logged in and out, so there will be duplicates.
(b) A number of other columns logging task/times etc but the one I am interested in (B:B), contains a tick (marlett font "a") to denote the driver has departed.

So what I simply want to do is to sort all the rows with a "tick" in Column B to the top and have these sorted in ascending order based on Column A.
Then all the rows with no "tick" in Column B to the bottom and have these sorted in ascending order based on Column A.

The cell range to sort is A7 to J500 (cells A1 to J6 are fixed and contain overview stats)

I have found a number of threads in the forum on "sorting" but they all involve quite complex scenarios and I cannot get my head round the basics.

Thanks and Regards,
Mike
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Mike

Perhaps you could turn the macro recorder on, perform the steps manually, turn the recorder off? Then have a look at the code to see if it needs tidying up/tweaking.

If you are still stuck after trying the above, post the code so far and describe the problems you are still having. A little bit of actual sample data (say 10-15 rows and 3-4 columns should do) would also help if there are still problems.
 
Upvote 0
I agree with peter. Use the macro recorder. The sort methods in vb really stink. :) they use the colons and equal signs for the elements, and that gets confusing as heck.
 
Upvote 0
Hi Guys,
I took your advice and recorded a macro, then copied that code into an existing sub as I wanted to merge a few other things (including Unprotect/Protect............ worked great and easier than struggling through VB for a newby like me!

Thanks,
Mike
 
Upvote 0
Hi Guys,
I took your advice and recorded a macro, then copied that code into an existing sub as I wanted to merge a few other things (including Unprotect/Protect............ worked great and easier than struggling through VB for a newby like me!

Thanks,
Mike
That's great Mike. :)

If it is working how you want then no need to fiddle with it any more. However, just remember that the recorder generally writes inefficient code (lots of 'selects' when they are not needed etc) so always be on the lookout for how to streamline it once the recorder has given you the basics.
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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