VBA Auto Sort Question

albert5445

New Member
Joined
Mar 25, 2011
Messages
6
Hello,
I've been trawling forums and Microsoft's site for a while but still can't wrap my head around creating a usable Auto Sort Macro. Any help would be much appreciated!

For whatever reason, I cannot attach the document so here is a simplified version of my spreadsheet in Text format: (Column C has this formula: =IF((B2<=25),"Yes","No"))
Column A | Column B | Column C
Ticker ||| Price |||||| Criteria
A ||||||| 24.00 ||||| Yes
AAPL ||| 26.00 |||||| No
ABC ||| 28.00 |||||| No
ABT ||| 22.00 ||||||| Yes

On a daily basis, the price (column B) will change, which will affect the Criteria column. I would like to be able to create something within VBA that will auto sort by Column C (a descending sort so all the Yes's are on top).
Seems pretty basic but my attempts thus far have been unsuccessful so hopefully I can get some pointers in the right direction.

Thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
you don't say which version of Excel you're using so here's a pointer for Excel 2007 upwards:
Code:
Sub blah()
With ActiveWorkbook.Worksheets("Sheet1")
  .Sort.SortFields.Clear
  .Sort.SortFields.Add Key:=Range("C1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
  With .Sort
    .SetRange ActiveWorkbook.Worksheets("Sheet1").Range("A1").CurrentRegion
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
  End With
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,949
Latest member
Dupuhini

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