This Excel macro filters a data set to display only the top X number of items in that data set in Excel. This means that the highest X number of items in a list will be displayed. This macro uses the autofilter feature in Excel and the xlTop10Items operator; however, this macro can display however many of the top items of a data set that you want to display. This is a versatile and easy to use macro to filter data in Excel.
To use this macro, simply replace the "#" with the amount of items from the top of the list or data set which you would like to display. Use integers and do not have decimals in the number. Also, you will need to update the range and field parameters to point to the data set that you are using in your worksheet in Excel.
All of the elements below often appear within autofilter macros.
Range
Field
Criteria
Operator
Sub AutoFilter_Top_X_Number_Items()
'Replace the "#" sign with the top number of items you would like to have displayed
Range("A1").AutoFilter Field:=1, Criteria1:="#", Operator:=xlTop10Items
End Sub