New to the Forum - looking for VBA Help in sorting selected cells

A3F3

New Member
Joined
Sep 9, 2023
Messages
4
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Been browsing this forum for a while - just found it. Amazing resources and very helpful people.

Here's a problem I'm working on that I'd love some help. Not a developer/VBA expert at all.

I have an excel spreadsheet full of data. I need to manually resort selected portions of the spreadsheet to the same construct each time.

My workflow is:

Select the rows (2 to 20 or so), then sort the rows based on Column L (numbers, want them sorted from high to low) and then Column C (words, want them sorted alphabetically).

I may have to do this in different areas of the spreadsheet, so want to be able to select the rows, then invoke the macro to run the above sort. I currently do this manually with the Sort & Filter function and/or using shortcuts Alt-A, S, S and then picking the columns L and C manually. Would love if I could just run a macro.

Thanks!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Could you post a copy of your sheet using the XL2BB add in? Also, how do you intend to select the rows of interest - obviously with the mouse, but do you want to select the entire range (column A to column whatever) or just select a range of rows in one column?
 
Upvote 0
I will try and use the addin - never used it before.

Ideally, I’d just select with the mouse the rows. As in highlight (on the far left) rows 6-18 and it would highlight all data in those rows. Then invoke the macro to run the sort on column K and C.
 
Upvote 0
OK, try the following on a copy of your sheet:
VBA Code:
Sub Sort_Part_Range()
    Selection.Sort Key1:=Cells(Selection.Row, 12), order1:=xlAscending, _
    Key2:=Cells(Selection.Row, 3), order2:=xlAscending, Header:=xlNo
End Sub
 
Upvote 0
OK, try the following on a copy of your sheet:
VBA Code:
Sub Sort_Part_Range()
    Selection.Sort Key1:=Cells(Selection.Row, 12), order1:=xlAscending, _
    Key2:=Cells(Selection.Row, 3), order2:=xlAscending, Header:=xlNo
End Sub
This worked great. Just had to change the ascending to descending and apply a shortcut and it was excellent. Thank you !!!!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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