Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Filter Data to Show the Top 10 Items from a Data Set in Excel - AutoFilter


Bookmark and Share

This Excel macro filters data in Excel in order to display the top 10 items from the data set. The macro uses the autofilter feature and xltop10items operator in Excel. The top 10 items from a list applies to number formatting in Excel and means the top ten highest values or numbers within the list.

This is a good way to narrow down results in Excel in order to better analyze large sets of data. To use the macro you only need to update the field and range numbers and apply them to your data set in Excel.


How Filter Macros Work

All of the elements below often appear within autofilter macros.

Range
    This should be the start of the data set, table, or list which you would like to filter. This can also be the entire range reference to the table. For example, if the table was from cell A1:D450, you could put that as the range or you could put A1 as the range. You can do this because the autofilter feature in Excel will automatically try to determine the total range which you would like to filter.
Field
    This is the number of the column within the data table that you would like to filter. The first field (1) is the very first column in the data set that will be filtered. This means that if your data starts in column B and your range is Range("B1") and you want to filter based on column D, you would put 3 in for the field.
Criteria
    This is the criteria by which you would like to filter. Some of the macros have symbols within the quotation marks after this argument and those symbols (such as <,>,*,?, etc.) should be left where they are in order to retain the functionality of the macro.
Operator
    You will not have to change this. This is simply the way to perform different types of filter features in Excel.
Where to install the macro:  Module

Excel Macro to Filter Data to Show the Top 10 Items from a Data Set in Excel - AutoFilter

Sub AutoFilter_Top_10_Items()

Range("A1").AutoFilter Field:=1, Criteria1:="10", Operator:=xlTop10Items

End Sub


Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

Pivot Table Filter Data Field To Show Items With Count More Than N - Excel

View Content
Hello,

Have a table of sales people,

Want to set rewards program for top sales people based on n# of sales that exceed $X.

so for the source range that feeds the pivot table, I have a vba decision derived decision column title "Huge Sale" that is applied to each sale (does this sale exceed $x, if true then put "yes" in decision column, else "no").

Now, what I am trying to figure out, on my pivot table, I want it only to show salespeople who have had at least n# of "Huge Sales". Is there a way I can set a filter on my pivot table to show only row groups where Count of Huge Sales exceeds n?

If I can do that, user inputs what a huge sale is ($ threshold value) and how many sales before reward (# threshold). And the table would just spit out the sales people to reward.

Any ideas?

Current Row labels a
Huge Sale (show "yes" only)
Salesperson

Data:
Count of huge sale

Show Items With No Data - Excel

View Content
hi,

I am working in simple pivot table (MS office 2007) and i want to segragate the data by department. I want to standadise the pivot table irrespective of whether the data is there or not.

Previously I was using office 2003, and I used an option called "show items with no data" under Pivot table option/Display Tab.

But in office 2007 this option is not selectable, not sure what is the reason.

Can some one help me in this?

Thanks in advance

zhannu

Show Items With No Data - Excel

View Content
I want to make this option of pivot table field setting enabled. But I have tons of Pivot tables.

Can Any one get the code for doing this for all the pivot tables in work sheet ?

It is for column area AND I am using excel 2003.


thank you.

Show All Data Autofilter Xl2007 - Excel

View Content
Why doesn't this work

Sub auto_close()
Dim Worksheet1 As Worksheet
Dim returnValue As AutoFilter

Set Worksheet1 = Worksheets("Prov Pmt Sched")
returnValue = Worksheet1.AutoFilter
End Sub

returns an Object variable or with block variable not set.

Ziggy

Excel Vba: Display Excel Autofilter Criteria. Show Auto Filter Criteria In Excel - Excel

View Content
This topic on Ozgrid provides just what I need, but limited to only 2 criteria - my VBA is not up to extending the code to the ten criteria that I need. Can anyone point me in the right direction please? VB:

Function AutoFilter_Criteria(Header As Range) As String  Dim strCri1 As String, strCri2 As String        Application.Volatile            With Header.Parent.AutoFilter          With .Filters(Header.Column - .Range.Column + 1)                        If Not .On Then Exit Function                                strCri1 = .Criteria1              If .Operator = xlAnd Then                  strCri2 = " AND " & .Criteria2              ElseIf .Operator = xlOr Then                  strCri2 = " OR " & .Criteria2              End If                        End With      End With                AutoFilter_Criteria = UCase(Header) & ": " & strCri1 & strCri2  End Function 


If you like these VB formatting tags please consider sponsoring me in support of injured Royal Marines



Pivot Table: Show Items With No Data - Excel

View Content
I have a pivot table with multiple Row fields and want to show a little less than what "Show Items with no data" displays. I am almost asking if there is a way individually select row fields..

First Row field is REGION: no problems here, dataset contains all possible Regions

Second Row field is Add Type:no problems here, dataset contains all possible Add Types

Third Row field is Add Detail: Here's where the problem is, as dataset does not contain all possible values... I want to show items here with no data, however I need it to correspond with the Add Type.

As an example, take the following two Add Types and their corresponding possible details:
Add Type = New Patient; Add Detail = Acquisition, Doctor, Hospital
Add Type = Other; Add Detail = Intensity, Modality, Accounting

Some of the Add Detail has no data, and I'd still like it to show. The problem is if I click "Show Items with no data" all Add Detail appears for both Add Types. I don't want the details corresponding with "Other" to show up with "New Patient".

Thoughts?

-Brian

Pivot - Show Items With No Data Not Working - Excel

View Content
Hi all,

I'm having an issue with my pivot table. I would like to keep all row elements visable even when there is no data. I have set the field setting "show items with no data" to true.

Still, when I update the pivot row elements with no data disappear.

How can I have all items showing?

Thanks in advance!

Enable Show Items With No Data In Pivot - Excel

View Content
Greets to all

Can some one help me to activate "enable show items with no data" in pivot options?

Thanks in advance

zhannu

Show Items With No Data In Pivot Table - Excel

View Content
I am using Excel for mac 2011 on a mac book pro running snow leopard. In previous versions of excel there was a feature that allowed you to "show items with no data". I can't seem to do this with excel 2011. I have clicked on the row label and selected filter select all. The row that ends up being missed is selected. Any suggestions would be greatly appreciated.

Thanks
Sam

Show Items With No Data On Rows And Columns - Excel

View Content
Hi,

I am using excel 2010 and in that a pivot table for getting data from a cube.Now when i retrieve data from the cube it is not showing data for which the values are null or zero.I have tried pivot table options >display>ticking both show items on rows and columns with no data...but that doesn't seem to work.Even in pivot tools>options>field settings>print & layout the check box is greyed out leaving me no option to check it.Can anyone tell me what could be the possible workaround for this?

Thanks

Random Tutorials
FV() Find the Future Value of Cash Today
         -Savings/Retirement Plan Calculations

(Intermediate)
Function and Formulas Lookup in Excel
(Easy)
AND(), OR(), and IF() Statements/Formulas
(Intermediate)
How to record a Macro - And what One is
(Easy)
Printing Multiple Worksheets and Workbooks
(Easy)
Password Protect Excel Workbook Files
(Easy)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com