I am trying to change the color of my bar graph based on each button that I click. And at the end of the code, I do not want it to select on the graph. Here is one of my code for the button. Hoping if there any way to make this code better or maybe go at it in a different direction. I am also trying to combine these two codes.
Sub Add_Value_Field
Dim pt As PivotTable
Dim pf As PivotField
Dim sField As String
Set pt = ActiveSheet.PivotTables(1)
sField = ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text
For Each pf In pt.DataFields
If pf.Name <> "Values" Then
pf.Orientation = xlHidden
End If
Next pf
pt.PivotFields(sField).Orientation = xlDataField
End Sub
With this code:
Sub Unselect()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullSeriesCollection(1).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoTheColorAccent2
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.PlotArea.Select
ActiveSheet.ChartObjects("Chart 1").Activate
End Sub
I hope this made it easier to understand.