[英]Set the chart colors to automatic in Excel VBA
我有一個宏,可將堆積的條形圖上的所有系列設置為相同的顏色,以及其他一些類似的代碼:
Sub RefreshLabels()
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Dim ch As Chart
ActiveSheet.ChartObjects("ProjectChart").Activate
Set ch = ActiveChart
ch.SetElement (msoElementDataLabelCenter)
Dim sc As SeriesCollection
Set sc = ch.SeriesCollection
Dim showLabel As Boolean
If (Range("showLabels").Value = "Y") Then
showLabel = True
Else
showLabel = False
End If
Dim sameColor As Boolean
If (Range("sameColor").Value = "Y") Then
sameColor = True
Else
sameColor = False
End If
Dim s As Series
For Each s In sc
If (sameColor = True) Then
s.Border.Color = RGB(Range("rgb_r"), Range("rgb_g"), Range("rgb_b"))
s.Interior.Color = RGB(Range("rgb_r"), Range("rgb_g"), Range("rgb_b"))
Else
'CODE HERE TO MAKE COLORS AUTOMATICALLY SELECTED FROM PALLETTE
End If
Set dl = s.DataLabels
dl.ShowSeriesName = showLabel
dl.ShowValue = False
Next
End Sub
但是,我需要選擇將系列更改回默認的堆疊條形圖的方式,並自動將顏色選擇為各種調色板。
讓我知道您是否需要其他信息。
好,解決了 您可以在圖表上調用一種方法來重置樣式:
ActiveChart.ClearToMatchStyle
希望能對某人有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.