Sort data w/ correct starting row

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
657
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I want to sort by G/L % (L:L), it sorts correctly but the sort begins in row 13, when it should be line 9. How can I make the sort start on line 9?
Thank you.

Here is the data Im working with:

The Whole Enchilada.xlsm
ABCDEFGHIJKLMNOPQ
8 Symbol Sector Type Shares Cost CURRENT MAX Value MIN Value Cost ValueMarket ValueGain/LossG/L %Weight(%)ExpirationStrikeExpires in:
9 $ -$ -$ -$ -$ -$ -$ -    
10 $ -$ -$ -$ -$ -$ -$ -    
11 $ -$ -$ -$ -$ -$ -$ -    
12 $ -$ -$ -$ -$ -$ -$ -    
13UKPIXBear MktBear10$ 11.66$ 12.12$ 12.29$ 11.66$ 116.60$ 121.20$ 4.603.95%4.6%  
14UVPIXBear MktBear10$ 20.97$ 21.62$ 21.80$ 20.83$ 209.70$ 216.20$ 6.503.10%8.2%  
15UHPIXBear MktBear10$ 14.15$ 14.56$ 14.81$ 14.15$ 141.50$ 145.60$ 4.102.90%5.5%  
16UXPIXBear MktBear10$ 22.46$ 22.87$ 23.12$ 22.35$ 224.60$ 228.70$ 4.101.83%8.8%  
17GSSFXBear MktBear10$ 5.81$ 5.84$ 5.85$ 5.81$ 58.10$ 58.40$ 0.300.52%2.3%  
18URPIXBear MktBear10$ 21.78$ 21.82$ 22.19$ 21.72$ 217.80$ 218.20$ 0.400.18%8.5%  
19RYAPXBear MktBear10$ 21.93$ 21.97$ 22.21$ 21.89$ 219.30$ 219.70$ 0.400.18%8.6%  
20UWPIXBear MktBear10$ 20.59$ 20.62$ 20.82$ 20.54$ 205.90$ 206.20$ 0.300.15%8.0%  
21GRZZXBear MktBear10$ 6.99$ 7.00$ 7.10$ 6.99$ 69.90$ 70.00$ 0.100.14%2.7%  
22RYARXBear MktBear10$ 28.45$ 28.49$ 28.71$ 28.41$ 284.50$ 284.90$ 0.400.14%11.1%  
23SOPIXBear MktBear10$ 14.23$ 14.25$ 14.42$ 14.21$ 142.30$ 142.50$ 0.200.14%5.6%  
24RYAFXBear MktBear10$ 54.05$ 54.06$ 55.90$ 54.05$ 540.50$ 540.60$ 0.100.02%21.1%  
25UCPIXBear MktBear10$ 7.26$ 7.25$ 7.77$ 7.25$ 72.60$ 72.50$ (0.10)-0.14%2.8%  
26UIPIXBear MktBear10$ 5.52$ 5.49$ 5.75$ 5.49$ 55.20$ 54.90$ (0.30)-0.54%2.2%  
27$ 2,558.50$ 2,579.60$ 21.100.82%
Bear Mkt
Cell Formulas
RangeFormula
G9:G26G9=IF($F9=0,0,MAX($F9,$G9))
H9:H26H9=IF($H9=0,$F9,MEDIAN($H9,$F9,0))
I13:I26,I9:I10I9=(E9*D9)
J9:J26J9=F9*D9
K9:K26K9=J9-I9
L9:L26L9=IF(K9<>0,K9/I9,"")
M9:M26M9=IF(I9<>0,I9/$I$27,"")
P9:P26P9=IF(OR($N9="",$N9="sold"),"",$N9-TODAY())
Q9:Q26Q9=IF(OR($N9="",$N9="sold"),"","day(s)")
F13:F26F13=VLOOKUP($A13,$A$53:$B$68,2,0)
B9:B26B9=IF(COUNTIF(Sectors!$A$3:$AA$50,A9)=1,INDEX(Sectors!$A$2:$AA$2,MAX((Sectors!$A$3:$AA$50=A9)*(COLUMN(Sectors!$A$2:$AA$2)))),"")
I27:K27I27=SUM(I9:I26)
L27L27=IFERROR((K27/I27),"")
Press CTRL+SHIFT+ENTER to enter array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D9:D26Cell Value="put"textNO
D9:D26Cell Value="call"textNO
B9:B26Expression=$N9="sold"textNO
B9:B26Expression=MOD(ROW(),2)=1textNO
A9:A26Expression=$N9="sold"textNO
A9:A26Expression=MOD(ROW(),2)=1textNO
C9:C26Cell Value="put"textNO
C9:C26Cell Value="call"textNO
I9:O26,C9:E26Expression=$N9="sold"textNO
F9:F26,H9:H26Expression=$F9=$H9textNO
F9:G26Expression=$F9=$G9textNO
I9:O26,C9:E26Expression=MOD(ROW(),2)=1textNO
L27Cell Value<0textNO
L27Cell Value>0textNO
K27Cell Value<0textNO
K27Cell Value>0textNO
D1,K9:L26Cell Value<0textNO
D1,K9:L26Cell Value>0textNO
K8:L8Expression=AVERAGE(K9:K26)<0textNO
K8:L8Expression=AVERAGE(K9:K26)>0textNO


Here is the Macro:

VBA Code:
Sub BearMkt_Sort_by_Gain()

    Workbooks("The Whole Enchilada.xlsm").Worksheets("Bear Mkt").Select
    
    Range("A9:Q26").Select
    ActiveWorkbook.Worksheets("Bear Mkt").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Bear Mkt").Sort.SortFields.Add2 Key:=Range("L9:L26") _
        , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Bear Mkt").Sort
        .SetRange Range("A9:Q26")
'        .Header = xlNo
'        .MatchCase = False
'        .Orientation = xlTopToBottom
'        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A9").Select
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

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