• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Defining Auto Filter Key Range

I've had this problem for a while now.


Been looking for a way to make this recorded macro of the auto filter much shorter.


I'm sure all of this isn't necessary if I only wish to sort in ascending order.


Also, to define the range on the sorter (when the range is not known).


ActiveWorkbook.Worksheets(1).AutoFilter.Sort.SortFields.Clear

ActiveWorkbook.Worksheets(1).AutoFilter.Sort.SortFields.Add Key:=Range( _

"A2:A44"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _

xlSortNormal

With ActiveWorkbook.Worksheets(1).AutoFilter.Sort

.Header = xlYes

.MatchCase = False

.Orientation = xlTopToBottom

.SortMethod = xlPinYin

.Apply

End With
 
Thanks Hui


I went with this, this was as short as I could modify it to my knowledge.

It also sorts the entire column if the range is not defined.


Worksheets(1).Range("A1").Sort _

Key1:=Worksheets(1).Columns("A"), _

Header:=xlGuess
 
Back
Top