PDA

View Full Version : Excel 2010 Slicer selection range



paradox34690
04-15-2013, 11:27 PM
Hi everyone!

I'm working on some Excel VBA right now and need to determine what the first and last values of a selected Slicers range are.

Example (and this is pretty much my exact case):

Slicer - "Date"
Contains all dates as MM/DD/YYYY

If a user selects one, and then shift-clicks another value to create a range of dates (let's say 03/01/2013 is the first date, 03/15/2013 is the second) How can I determine what those first and second selected values are and assign them to 2 variables?

This is specifically what I need as I then need to work with a SQL table to do other calculations from those 2 variables.

Any thoughts? :dunno

Jan Karel Pieterse
04-16-2013, 12:46 AM
You could use a function like this one perhaps:

Public Function GetSelectedItemsOfSlicer(oSl As Slicer) As Variant
Dim vSelected() As Variant
Dim oSi As SlicerItem
Dim lCt As Long
ReDim vSelected(1 To 1)
For Each oSi In oSl.SlicerCache.SlicerItems
If oSi.Selected Then
lCt = lCt + 1
ReDim Preserve vSelected(1 To lCt)
vSelected(lCt) = oSi.Value
End If
Next
GetSelectedItemsOfSlicer = vSelected
End Function