Macro for selected cells

mmackoka

New Member
Joined
Apr 24, 2022
Messages
6
Platform
  1. MacOS
Need to use a macro on cells what I would like to select. I've recorded one but no luck with it. Can someone please help me with it?

Range("U16:X36").Select
ActiveWorkbook.Worksheets("eBay-edit-price-quantity-templa").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("eBay-edit-price-quantity-templa").Sort.SortFields. _
Add2 Key:=Range("U16:U36"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("eBay-edit-price-quantity-templa").Sort.SortFields. _
Add2 Key:=Range("W16:W36"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("eBay-edit-price-quantity-templa").Sort
.SetRange Range("U16:X36")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Thank you!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You will make it much easier for people on this forum to help you if you provide a sample of your actual data using the XL2BB Tool.

If you're talking about sorting the specific range you mention ("U16:X36") then the following should work for you (assumes row 16 is your header row).

VBA Code:
Option Explicit
Sub mmackoka_1()
    Dim ws As Worksheet
    Set ws = Worksheets("eBay-edit-price-quantity-templa")
    
    ws.Range("U16:X36").Sort _
    Key1:=ws.Range("U16"), order1:=xlAscending, _
    Key2:=ws.Range("W16"), order2:=xlAscending, Header:=xlYes
    ws.Sort.SortFields.Clear
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
Members
449,093
Latest member
Mnur

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