• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Find top 2 data from data set

riya

Member
Hi All,
Good Day,
Can you please suggest how to find top two data from the data sets.
 

Attachments

  • tests.xlsx
    9.8 KB · Views: 5
Personally, I'd just use PivotTable and use TOP N filter.

Code:
Sub Demo()
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Record")
    .ClearAllFilters
    If [F2].Value = 0 Or [F2].Value > .PivotItems.Count Then
        Exit Sub
    Else
        .PivotFilters.Add2 _
            Type:=xlTopCount, DataField:=ActiveSheet.PivotTables("PivotTable1"). _
            PivotFields("Sum of Populations"), Value1:=[F2].Value
    End If
End With
End Sub

See attached.
 

Attachments

  • MS_tests.xlsm
    26 KB · Views: 3
Back
Top