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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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