Sort / subsort a range of cells based on the cell selected ??

James 35

New Member
Joined
Jan 28, 2013
Messages
7
Hi I'd like to automate excels inbuilt sort / subsort for a non static range of cells ...
The range is based on
5 columns including and adjacent to the selected cell and say 66 rows down ...
Ie . EV4:EZ70
The initial range being sorted alphabetically by cells EY4:EY70

Then a subsort numerically EW4:EW70

Only to sort cells in the range that have values in EV4:EV70...

When I record a macro I get this ??

Code:
Sub sortexample()

'

' sortexample Macro

'

 

'

    Range("EV4:EZ70").Select

    ActiveWorkbook.Worksheets("Period 12").Sort.SortFields.Clear

    ActiveWorkbook.Worksheets("Period 12").Sort.SortFields.Add Key:=Range( _

        "EY4:EY70"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _

        xlSortNormal

    ActiveWorkbook.Worksheets("Period 12").Sort.SortFields.Add Key:=Range( _

        "EW4:EW70"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _

        xlSortNormal

    With ActiveWorkbook.Worksheets("Period 12").Sort

        .SetRange Range("EV4:EZ70")

        .Header = xlGuess

        .MatchCase = False

        .Orientation = xlTopToBottom

        .SortMethod = xlPinYin

        .Apply

    End With

    ActiveWindow.SmallScroll Down:=-48

Any help is appreciated ! Thanks
 
Last edited by a moderator:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Cross posted https://www.excelforum.com/excel-pr...ange-of-cells-based-on-the-cell-selected.html

Cross-Posting
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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