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 Bottom X Number of Items in Excel - AutoFilter


Bookmark and Share

This free Excel macro filters a data set to show the bottom X number of items from that data set. This macro is really great because you can easily customize it to choose how many items you want to be displayed after you run the filter.

To determine the number of items to display simply replace the "#" sign in the macro with the number of items which you want to have displayed. Also, change the range reference to point to the first cell of the data which you would like to filter.


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 Bottom X Number of Items in Excel - AutoFilter

Sub AutoFilter_Bottom_X_Number_Items()
'Replace the "#" sign with the bottom number of items you would like to have displayed

Range("A1").AutoFilter Field:=1, Criteria1:="#", Operator:=xlBottom10Items

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

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



Report Filter To Show All Items - Excel

View Content
Is there a way to show all selected items in the cell rather than the "Multiple Items" display?

So if I had a Report Filter for "Teams" that contains 3 items, this would be shown:

A1____B1
Teams Redsox, Yankees, Rays

instead of

A1____B1
Teams (Mutliple Items)


Is there an option for this or does this require a macro?

Thanks,
Sly

Print Pivottable - Show All Selected Items In Page Filter - Excel

View Content
Hi all,

My end-users intensively use the pivottable. But they also want to print
them. When they use a date-dimension in the page filter, and select multiple
days/months/years, the filter show the message "Multiple items selected".
This message also appears when they print the page.

Is there a way to show their selected parameters?

Thx!


Displaying The Top/bottom N Items In Excel 2007 - Excel

View Content


Select a cell in a Row Labels field -> right-click, select Filter -> Top 10.



Counting Number Of Items After Filter - Excel

View Content
hi!

i would like to coun the numbers of items in a colom after using auto filter.

right now im using countif but it counts even the filtered out items..

is there a way around this ?

thanks

Excel 2007 [auto]filter Ignores Bottom Row Of Range - Excel

View Content
Imagine a 3x5 table as follows, starting in cell A1:

RowNumber; Region; SalesValue
1;North;$20
2;North;$11
3;South;$44
4;North;$29
5;South;$11

Place the cursor in cell A1 and select "Filter".
Everything works fine, Excel correctly detects 3 cols and 6 rows (inc. header).

Now make the row numbers 'dynamic' as follows:
Replace the hard coded row number in A2 with the following formula:
=SUBTOTAL(3,$C$2:C2), then copy down.
The RowNumbers are now 'dynamic', i.e. they are always consecutive, even when filtered.

Place the cursor in cell A1 and select "Filter".
Excel detects 3 cols and ONLY 5 ROWS (inc. header).
The last row is never detected.
Manually defining the list range (Advanced) doesn't work either.
Excel readjusts the range to exclude the last row,

Surely this is a bug?

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.

How Do I Show Number Of Records That Meet Criteria Filter - Excel

View Content
I have a large spreadsheet containing several hundred rows of data. I want
to filter the list and I want to be able to show the number of records that
match the filter criteria. For example, un-filtered the total number of
records in the list is displayed and, when filtered, the number of records in
the list that match the criteria is displayed.

Can onyone help me please?

Kind regards,

Cliff


Random Tutorials
Net Present Value / Discounted Cash Flow Calculations
(Intermediate)
HLOOKUP() Function - Introduction
(Intermediate)
AND(), OR(), and IF() Statements/Formulas
(Intermediate)
Link Cells Between Worksheets
(Easy)
Consolidate & Combine Data from Separate Worksheets or Workbooks(Excel Files)
(Intermediate)
How to record a Macro - And what One is
(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