VBA Sort two columns

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hi.
Column B there are a bin of numbers, column C the frequency of this numbers.
In order for me to RANK them, I have to Editing with sort & filter
I want to find a real short way to code this,

example:
1596395464753.png

So the macro I got is:
VBA Code:
//////////////////////////////////////////////----COPY AND PASTE -----/////////////////////////////////////////////////

Range("H2:I37").Copy
Range("T2").PasteSpecial Paste:=xlPasteValues

'///////////////////////////////////////////////--------SORTING--------///////////////////////////////////////////////////

Range("T2:U37").Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("U2:U37") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("T1:U37")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
End With
any way to trim this.
thanks.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
How about
VBA Code:
Sheets("sheet1").Range("T2:U37").Sort key1:=Sheets("sheet1").Range("U2"), order1:=xlAscending, Header:=xlYes
 
Upvote 0
Thank you Mr. Fluff, I have a little question, after you see the ilustration
1596398269292.png

I expect "cero" instead of one {"the arrow mark"), I tried to see if I can to fix but not, sorry.
 
Upvote 0
Try
VBA Code:
Sheets("sheet1").Range("T1:U37").Sort key1:=Sheets("sheet1").Range("U1"), order1:=xlAscending, Header:=xlYes
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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