VBA for Slicer Formatting

Noofus

New Member
Joined
Dec 27, 2018
Messages
4
I am trying to create a macro (button) to format all slicers to a certain style on the active worksheet. I have multiple worksheets that are nearly identical (copied from a master sheet), but the following code only works on the original sheet. How do I change the slicer name to apply to all, not a specific slicer?
Code:
ActiveSheet.Shapes.Range(Array("Scope")).SelectActiveSheet.Shapes.Range(Array("Scope", "BREAKOUT")).Select
ActiveWorkbook.SlicerCaches("Slicer_Scope").Slicers("Scope").Style = _
        "SlicerStyleDark1"
ActiveWorkbook.SlicerCaches("Slicer_BREAKOUT").Slicers("BREAKOUT").Style = _
        "SlicerStyleDark1"
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You could try looping through all the slicers in the workbook, something like this.
Code:
Dim slc As SlicerCache
Dim sl As Slicer
Dim I As Long

    For Each slc In ActiveWorkbook.SlicerCaches
        For I = 1 To slc.Slicers.Count
            Set sl = slc.Slicers(I)
            ' code to format slicer
        Next I
    Next slc
 
Upvote 0
Thanks for responding. I tried this, adding the slicer style code. I don't get any errors, but nothing changes either. What am I missing?
Code:
Sub BlueSheet()
Dim slc As SlicerCache
Dim sl As Slicer
Dim I As Long


    For Each slc In ActiveWorkbook.SlicerCaches
        For I = 1 To slc.Slicers.Count
            Set sl = slc.Slicers(I)
            Style = "SlicerStyleDark4"
        Next I
    Next slc
End Sub
 
Upvote 0
This is how you would apply the style to the slicer.
Code:
sl.Style = "SlicerStyleDark4"
 
Upvote 0
This is how you would apply the style to the slicer.
Code:
sl.Style = "SlicerStyleDark4"

Thank you. That worked, but now it is changing the style of all slicers throughout the workbook. How do I limit it to just the active sheet?
 
Upvote 0
Cross posted http://www.vbaexpress.com/forum/showthread.php?64327-VBA-for-Slicer-amp-Table-Formatting

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Cross posted http://www.vbaexpress.com/forum/showthread.php?64327-VBA-for-Slicer-amp-Table-Formatting

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

Thanks for the info. Forum etiquette is new to me . . .
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,548
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top