Sort Already Selected Range

AWiseGuy

New Member
Joined
Dec 3, 2015
Messages
9
I have a spreadsheet with multiple parts on one sheet. Each part has a different number of rows, but the key column is always the same.

I want to be able to highlight the relevant range, then invoke a macro to sort that range. Then I want to highlight another range and invoke the macro to sort only that range, etc.

This is a mock up of what I'm looking to do. I want to highlight a range (Task through last Hours), then invoke the macro to sort by Hours.
Site 1
TaskAssignedHours
Job1Smith25
Job2Jones32
Job3Silver15
Site 2
TaskAssignedHours
Job1Smith25
Job2Jones32
Job3Silver15
Job 4Wilson8
Job 5Smith12
Site 3
TaskAssignedHours
Job1Smith25
Job2Jones32

<colgroup><col span="2"><col></colgroup><tbody>
</tbody>
 
Assuming exactly 10 columns in my dataset with one blank column in the middle means in English 11 columns and as stated there is a cell with "Site" above the "headers"

There is a title block above the header row to identify each block of data ("Site").

and a empty row between the areas
with blank lines between each section that needs to be sorted

then the code below will work if you select an cell in the area, as long as it is to the left of the empty column and it does away with the inefficient use of select/selection.

Code:
Sub SortRangeZ()
    With ActiveCell.CurrentRegion
        With .Offset(1).Resize(.Rows.Count - 1, 11)
            .Sort Key1:=.Cells(1, 3), Header:=xlYes
        End With
    End With
End Sub
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Apply .SetRange Selection
Couldn't get the quick commands to work, but the macro fails on the .SetRange Range(Active) command - it doesn't like the keyword Active. I don't think it matters , but if it makes a difference, I'm using Excel 2010
 
Upvote 0

Forum statistics

Threads
1,221,539
Messages
6,160,412
Members
451,644
Latest member
hglymph

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