Sub topic 12
Filtering visually with slicers
This chapter assumes you can create a table, give it a name, and use the filter buttons in its header row. It also assumes you know what the total row does. You need Excel 2013 or later (Microsoft 365 included) and a workbook saved as .xlsx, .xlsm, or another format that supports slicers.
What a slicer is
A slicer is a floating panel of buttons, one button for each distinct value in a table column. Clicking a button filters the table to the rows with that value. The selected buttons are highlighted, so you can see the current filter without opening a drop-down list.
A slicer does the same job as the filter button in a column header. The difference is that the slicer stays visible on the sheet. That helps in two cases:
- You are building a dashboard or report that other people will use without learning the filter menus.
- You want to see at a glance which filters are active, for example "Region: West, North" and "Status: Open".
The table in this chapter is SalesTable, with the columns Date, Region, Product, Quantity, Unit Price, and Amount.
Inserting a slicer
- Click any cell inside the table.
- On the Table Design tab, choose Insert Slicer.
- In the dialog, tick the columns you want a slicer for, for example Region and Product.
- Click OK.
Excel creates one slicer per ticked column and places them over the sheet, stacked on top of each other. Drag them to a free area. Choose an area that the table cannot grow into, because a table grows downward as you add rows and a slicer can end up covering new data.
You can also use Insert > Slicer on the Ribbon while a table cell is selected. It opens the same dialog.
Using the buttons
| Action | Result |
|---|---|
| Click a button | Shows only rows with that value. All other buttons are deselected. |
| Ctrl+click another button | Adds that value to the selection. |
| Click the multi-select button (the icon at the top right of the slicer) | Each click toggles a button, so you do not need to hold Ctrl. |
| Click the clear-filter icon (a funnel with a red cross) | Removes the filter for that slicer only. |
| Drag across several buttons | Selects the range of adjacent buttons. |
Several slicers combine with AND logic. If Region is West and Product is Widget, the table shows only rows that satisfy both. Several selected buttons inside one slicer combine with OR logic. Selecting West and North in Region shows rows from either region.
Slicers and header filters share one filter
A slicer is another way to control the same column filter that the header drop-down controls. They are not separate filters. If you pick West in the Region slicer, the Region header button shows the filter icon. If you then clear the filter from the header menu, the slicer buttons reset.
This explains a common confusion. If a table looks short and the slicer shows nothing selected, check the other columns. A filter set through another column's header button, or through another slicer, can still be hiding rows.
Slicers do not replace every header filter option. A slicer can only select discrete values. It cannot apply "greater than 100", "begins with", or a date range. For those filters, keep using the header buttons. You can use both on the same table.
Slicers and totals
Hidden rows are why the total row uses SUBTOTAL. When you filter with a slicer, a formula such as this one still counts hidden rows:
=SUM(SalesTable[Amount])The total row formula ignores rows hidden by a filter:
=SUBTOTAL(109,SalesTable[Amount])So the usual setup is to show the total row, choose Sum for Amount, and place the slicers next to the table. Each button click then updates the visible total. A formula outside the table that must follow the slicer should use SUBTOTAL or AGGREGATE in the same way. A plain SUM or COUNTIF does not react to the filter.
=SUBTOTAL(103,SalesTable[Product])This counts the visible non-empty entries in the Product column. Function number 103 is COUNTA that ignores filtered-out rows.
Configuring a slicer
Click a slicer and open the Slicer tab on the Ribbon. The settings you will use most are below.
Caption and name
The caption is the title at the top of the slicer. The name is what Excel and VBA use. They start out the same, for example Region. Change the caption to something readable for your audience, such as "Sales region", without changing the name.
Columns, button size, and layout
The Columns box sets how many columns of buttons the slicer uses. A slicer with 12 month names fits better as 4 columns of 3 rows than as one tall list. The Buttons group sets button height and width. Resize the slicer by dragging its corners.
Slicer settings
Right-click the slicer and choose Slicer Settings. The useful options are:
- Sort: Ascending, descending, or the order of a custom list. The default order is ascending A to Z or smallest to largest.
- Hide items with no data: Hides buttons for values that no row currently has. With cross-filtering between slicers, this makes the buttons shrink to values that are still possible.
- Visually indicate items with no data: Greys out those buttons. This is on by default.
- Show items deleted from the data source: Keeps buttons for values that no longer exist in the table. Leave it off unless you have a reason to keep them.
Styles
The Slicer tab includes a gallery of slicer styles. These are separate from table styles, so you can match colors or choose a neutral style.
Placement and sheet behavior
A slicer is a shape on the worksheet. It does not sit in a cell. In Size & Properties you can choose whether it moves and sizes with cells, moves but does not size with cells, or does not move at all. If you hide the columns or rows behind a slicer, a slicer set to move and size with cells can shrink or disappear. Choosing Don't move or size with cells avoids this.
Connecting several tables
A table slicer controls only the table it was created from. Unlike a PivotTable slicer, it has no Report Connections command, so you cannot connect it to a second table. If you need one set of buttons to filter several tables, use PivotTables built from the same data model or build the filtering in VBA.
Common problems
- A button you expect is missing. The column has no rows with that value, or a different filter has already hidden every row that has it and Hide items with no data is on.
- The slicer covers new rows. The table grew under it. Move the slicer beside the table, not above or below it.
- The Insert Slicer command is greyed out. The active cell is not inside a table, the workbook is in an old file format, or the sheet is protected. Click a table cell, save as
.xlsx, and unprotect the sheet. - A total outside the table ignores the slicer. The formula uses
SUMorCOUNTIF. Switch toSUBTOTALorAGGREGATE. - Slicers disappear after converting the table to a range. A slicer needs a table, so a normal range cannot keep it. Convert back only when you no longer need the slicer.
Controlling slicers with VBA
Slicers are exposed through the SlicerCaches collection. The code below adds a slicer for the Region column of SalesTable. It then selects only the West button and shows how to clear the filter.
Sub AddRegionSlicer()
Dim ws As Worksheet
Dim tbl As ListObject
Dim sc As SlicerCache
Set ws = ActiveSheet
Set tbl = ws.ListObjects("SalesTable")
Set sc = ThisWorkbook.SlicerCaches.Add2(tbl, "Region")
sc.Slicers.Add ws, , "RegionSlicer", "Sales region", 20, 420, 140, 150
End Sub
Sub FilterToWest()
Dim sc As SlicerCache
Dim itm As SlicerItem
Set sc = ThisWorkbook.SlicerCaches("Slicer_Region")
sc.ClearManualFilter
For Each itm In sc.SlicerItems
itm.Selected = (itm.Name = "West")
Next itm
End Sub
Sub ClearRegionFilter()
ThisWorkbook.SlicerCaches("Slicer_Region").ClearManualFilter
End SubThe first macro creates a slicer cache, which holds the filter state, and a slicer, which is the visible panel. The last four arguments of Slicers.Add are the top, left, width, and height in points. Excel names the cache Slicer_ followed by the column name, with spaces replaced by underscores. If you are not sure of the name, check it with ThisWorkbook.SlicerCaches(1).Name. Run AddRegionSlicer only once, because a second run for the same column raises an error or creates a duplicate.
Exercise
You filter SalesTable with a Region slicer and select West. A cell outside the table contains =SUM(SalesTable[Amount]) and still shows the grand total. The total row of the table shows only the West total. Why do they differ, and how do you fix the outside cell?
Show answer
The total row uses SUBTOTAL(109, ...), which skips rows hidden by a filter. SUM counts every row in the column, hidden or not. Change the outside cell to =SUBTOTAL(109,SalesTable[Amount]) so it follows the slicer.
Exercise
A colleague wants to show only orders where Amount is greater than 500 using a slicer. Can a slicer do this? If not, what should they use, and will the slicer still work alongside it?
Show answer
No. A slicer can only select discrete values, so it cannot apply a comparison such as "greater than 500". They should use the Amount header filter, then choose Number Filters > Greater Than. The slicer and the header filter act on the same table filter, so both apply together, and rows must pass both to be shown.