• 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

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

Back
Top