Need Auto-sort macro to ignore blank

aggiemarine07

New Member
Joined
Nov 5, 2013
Messages
46
Howdy!

I am trying to have a sheet auto-sort the data in it. Ive been successful in that it auto-sorts the data however, Ive been unsuccessful in that when I run the macro it puts all the blanks at the top. Can someone help me adjust the below formula to ignore blanks? Thanks!

Below is what I have:

Sub DoSort()
Dim ws As Worksheet
Set ws = Worksheets(2)
ws.Range("C5", Range("C805").End(xlUp)).Select Key1:=ws.Range("C5"), Order1:=xlDescending, _
Key2:=ws.Range("L3"), Order2:=xlDescending, Header:=xlYes

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You are sorting a range going down column C using a Key in column L?
Also to sort you should use .sort, not .select
 
Upvote 0
You are sorting a range going down column C using a Key in column L?
Also to sort you should use .sort, not .select


The macro should be sorting on column c (names) first then sorting on column l (group number) second. Do you know how to modify this or rewrite it completely to where it ignores blank cells? Thanks
 
Upvote 0
Are you looking to sort them separately(just column C using key C5 and then just column L using key L3) or a whole range going from column C to L using two levels of sorting?
 
Upvote 0
Are you looking to sort them separately(just column C using key C5 and then just column L using key L3) or a whole range going from column C to L using two levels of sorting?

My intent is to sort columns c through ae (yes 28 columns) between rows 6 and 805.

I want to sort them in alphabetical order first (column C) and then group number if there is a tie (column L) ignoring blank cells.
 
Upvote 0
Are you looking to sort them separately(just column C using key C5 and then just column L using key L3) or a whole range going from column C to L using two levels of sorting?

Any thoughts on how it could be altered to do what I need it to do? Thanks.
 
Upvote 0
if your range has headers in row 5, then u can try

Range("C6:AE805").Sort [C5], xlAscending, [L5], , xlAscending
 
Upvote 0
if your range has headers in row 5, then u can try

Range("C6:AE805").Sort [C5], xlAscending, [L5], , xlAscending

Where do I put this in my code? currently I have:

Sub DoSort()
Dim ws As Worksheet
Set ws = Worksheets(2)
ws.Range("C6:AE805").Sort [C5], xlAscending, [L5], , xlAscending

But I keep getting a runtime error 424.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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