Need help adding "Sort" function (with named range) into autofilter code

Faintkitara

Board Regular
Joined
Jun 23, 2016
Messages
59
Hello,

I am having trouble adding the sort function into code that autofilters based off of criteria. I would like for this code to sort Greatest to Least based off of a specific column name ("Prior" or P in the code).

I am also not sure if I should apply the filter criteria and then sort or vice versa.

Here is what I have. What should I add?

Code:
Set Heading = Worksheets("Backlog").Range("A4")a = Application.WorksheetFunction.Match(P, Range("A4:JD4"), 0)
Worksheets("log").Range("A4:EX4").AutoFilter
Heading.AutoFilter Field:=a, Criteria1:=">2499"
  
Const Row  As Integer = 4
LC = Cells(Row, Columns.Count).End(xlToLeft).Column


For H = LC To 1 Step -1
      If (Cells(Row, H) = C) Then
      customercolumn = H
      End If
      Next
     
    lrq = Cells(Rows.Count, customercolumn).End(3).Row
    Worksheets("log").Range(Cells(Row, customercolumn), Cells(lrq, customercolumn + 1)).Copy _
    Destination:=Worksheets("Pivot").Range("N4:O10000")
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Figure out the answer to my question:

Code:
Set Heading = Worksheets("log").Range("A4")
a = Application.WorksheetFunction.Match(P, Range("A4:JD4"), 0)
Worksheets("Backlog").Range("A4:EX4").AutoFilter
Heading.AutoFilter Field:=a, Criteria1:=">2499"
Set Sorter = Worksheets("log").Range("A4:JD4").Find(What:=P, MatchCase:=False)
    ActiveWorkbook.Worksheets("log").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("log").AutoFilter.Sort.SortFields.Add Key:= _
        Sorter, SortOn:=xlSortOnValues, Order:=xlDescending, _
        DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("log").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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