0% found this document useful (0 votes)
174 views1 page

Chart VBA Code

This VBA code refreshes two pivot tables on a worksheet and adds data labels to the series in a chart. It declares variables for a chart object, series, series iterator, and worksheet. It sets the worksheet and chart objects, then loops through each series in the chart to add data labels showing the series name but not the values. It then refreshes the pivot caches for two pivot tables.

Uploaded by

jignesh142
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
174 views1 page

Chart VBA Code

This VBA code refreshes two pivot tables on a worksheet and adds data labels to the series in a chart. It declares variables for a chart object, series, series iterator, and worksheet. It sets the worksheet and chart objects, then loops through each series in the chart to add data labels showing the series name but not the values. It then refreshes the pivot caches for two pivot tables.

Uploaded by

jignesh142
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Private Sub CommandButton1_Click()

Dim Dim Dim Dim

cht As Chart srs As Series '# Series variable' s As Long '# Series iterator' ws As Worksheet

Set ws = ActiveSheet Set cht = ws.ChartObjects("Chart 2").Chart '## Modify as needed.' For Each srs In cht.SeriesCollection With srs s = s + 1 .ApplyDataLabels With .DataLabels .ShowSeriesName = True .ShowValue = False End With End With ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh Next End Sub

You might also like