vba Sort with Criteria

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
684
Office Version
  1. 2019
Platform
  1. Windows
Hello,
Looking to Sort (A:P) by G/L % (L:L) excluding if Column (N:N) is a certain Value (ie "sold").
Thanks.

Cell Formulas
RangeFormula
G9:G21G9=IF($F9=0,0,MAX($F9,$G9))
H9:H21H9=IF($H9=0,$F9,MEDIAN($H9,$F9,0))
I9:I21I9=IF($A9<>"",IF($C9="Long",D9*E9,IF($C9="Call",((D9*E9)*100),IF($C9="Put",((D9*E9)*100),""))),"")
J9:J21J9=IF($A9<>"",IF($C9="Long",D9*F9,IF($C9="Call",((D9*F9)*100),IF($C9="Put",((D9*F9)*100),""))),"")
K9:K21K9=IF($A9="","",J9-I9)
L9:L21L9=IF($A9="","",K9/I9)
M9:M21M9=IF($A9="","",J9/$J$22)
C21,C19,C12:C17,C9:C10C9=IF(ISTEXT($A9),"Call","")
P21,P19,P9:P17P9=IF(OR($N9="",$N9="sold"),"","day(s)")
B9:B21B9=IF(COUNTIF(Sectors!$A$2:$ABJ$47,$A9)=1,INDEX(Sectors!$A$2:$ABK$2,MAX((Sectors!$A$2:$ABJ$47=$A9)*(COLUMN(Sectors!$A$2:$ABK$2)))),"")
O9:O21O9=IF(OR($N9="",$N9="sold"),"",$N9-TODAY())
Press CTRL+SHIFT+ENTER to enter array formulas.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hello,
Looking to Sort (A:P) by G/L % (L:L) excluding if Column (N:N) is a certain Value (ie "sold").
Thanks.

Cell Formulas
RangeFormula
G9:G21G9=IF($F9=0,0,MAX($F9,$G9))
H9:H21H9=IF($H9=0,$F9,MEDIAN($H9,$F9,0))
I9:I21I9=IF($A9<>"",IF($C9="Long",D9*E9,IF($C9="Call",((D9*E9)*100),IF($C9="Put",((D9*E9)*100),""))),"")
J9:J21J9=IF($A9<>"",IF($C9="Long",D9*F9,IF($C9="Call",((D9*F9)*100),IF($C9="Put",((D9*F9)*100),""))),"")
K9:K21K9=IF($A9="","",J9-I9)
L9:L21L9=IF($A9="","",K9/I9)
M9:M21M9=IF($A9="","",J9/$J$22)
C21,C19,C12:C17,C9:C10C9=IF(ISTEXT($A9),"Call","")
P21,P19,P9:P17P9=IF(OR($N9="",$N9="sold"),"","day(s)")
B9:B21B9=IF(COUNTIF(Sectors!$A$2:$ABJ$47,$A9)=1,INDEX(Sectors!$A$2:$ABK$2,MAX((Sectors!$A$2:$ABJ$47=$A9)*(COLUMN(Sectors!$A$2:$ABK$2)))),"")
O9:O21O9=IF(OR($N9="",$N9="sold"),"",$N9-TODAY())
Press CTRL+SHIFT+ENTER to enter array formulas.
I'm using the following Macro, which works. But doesn't exclude a certain value.
VBA Code:
Sub ETNA_Sort_by_Gain()

    Workbooks("The Whole Enchilada.xlsm").Worksheets("ETNA").Select
    
    Range("A9").Select
    Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).Select
    
    ActiveWorkbook.Worksheets("ETNA").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("ETNA").Sort.SortFields.Add2 Key:=Range("L9", Range("L9").End(xlDown)) _
        , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("ETNA").Sort
        .SetRange Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column))
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A9").Select
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,154
Members
452,615
Latest member
bogeys2birdies

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