vba compare and order in new row

Seeker2013

New Member
Joined
Jun 2, 2014
Messages
12
i have a header, let say number 1-20
A1-B1-C1-D1-E1-F1-G1-H1-I1-J1-K1-L1-M1-N1-O1-P1-Q1-R1-S1-T1
1--2--3--4--5--6--7--8--9-10-11-12-13-14-15-16-17-18-19-20 (this is the header)
14-16-25-22-21-13-14-20-07-05-13-29-10-12-07-11-08-15-02-06 (this is 2nd row, represent the frequency)
questions:
how can i use the vba to compare the frequency and place on row 3 from biggest figure to smallest figure,
and on row 4 from smallest figure to biggest figures?



thank you very much!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
VBA is not necessary,
in cell A3 paste =SMALL($A$2:$T$2,COLUMN())and copy across to row T
in cell A3 paste =LARGE($A$2:$T$2,COLUMN())and copy across to row T
 
Upvote 0
As Kieran indicated, VBA is not necessary, but here is a VBA solution anyway. But Kieran's solution appears much simpler.

Code:
Option Explicit


Sub as11()


    Range("A2:T2").Copy Range("A3")
    Application.CutCopyMode = False
    Range("A3:T3").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A3:T3"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A3:T3")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlLeftToRight
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A3:T3").Copy Range("A4")
    Application.CutCopyMode = False
    Range("A4:T4").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A4:T4"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A4:T4")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlLeftToRight
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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