title | keywords | f1_keywords | api_name | ms.assetid | ms.date | ms.localizationpriority | ||
---|---|---|---|---|---|---|---|---|
Slicers.Add method (Excel) |
vbaxl10.chm903077 |
|
|
f2632dee-e8fb-440c-cad8-2dd2f7e37739 |
05/16/2019 |
medium |
Creates a new slicer and returns a Slicer object.
expression.Add (SlicerDestination, Level, Name, Caption, Top, Left, Width, Height)
expression A variable that represents a Slicers object.
Name | Required/Optional | Data type | Description |
---|---|---|---|
SlicerDestination | Required | Variant | A String that specifies the name of the sheet, or a Worksheet object that represents the sheet, where the resulting slicer will be placed. The destination sheet must be in the workbook that contains the Slicers object specified by expression. |
Level | Optional | Variant | For OLAP data sources, the ordinal or the Multidimensional Expression (MDX) name of the level on which the slicer creation is based. Not supported for non-OLAP data sources. |
Name | Optional | Variant | The name of the slicer. Excel automatically generates a name if one is not specified. The name must be unique across all slicers within a workbook. |
Caption | Optional | Variant | The caption of the slicer. |
Top | Optional | Variant | The initial vertical position of the slicer, in points, relative to the upper-left corner of cell A1 on a worksheet. |
Left | Optional | Variant | The initial horizontal position of the slicer, in points, relative to the upper-left corner of cell A1 on a worksheet. |
Width | Optional | Variant | The initial width, in points, of the slicer control. |
Height | Optional | Variant | The initial height, in points, of the slicer control. |
Slicer
This example adds a SlicerCache object by using the OLAP data source AdventureWorks, and then adds a Slicer object to filter on the Country field.
Sub CreateNewSlicer()
ActiveWorkbook.SlicerCaches.Add("Adventure Works", _
"[Customer].[Customer Geography]").Slicers.Add ActiveSheet, _
"[Customer].[Customer Geography].[Country]", "Country 1", "Country", _
252, 522, 144, 216)
End Sub
[!includeSupport and feedback]