尝试在雷达图上分配自定义标记颜色和透明度级别时,我被 VBA 挡住了。我读过订单存在一些问题,但无论我在哪里尝试 .transparency 参数,我都会收到以下错误:对象不支持此属性或方法。
如果我在下面的代码中注释掉 .transparency 行,我会得到一个很棒的雷达图,其中的标记由 rngColors 中的值着色。我只想让它们透明,这样底层的线图也可以通过。任何帮助或建议将不胜感激。
问候,亚当
Sub colorPoints()
'Must select chart when running macro
Dim x As Long
Dim rngColors As Range
Set rngColors = Range("H8:H57") 'set range of RGB color
For x = 1 To ActiveChart.SeriesCollection(1).Points.Count
With ActiveChart.SeriesCollection(1).Points(x)
.Format.Fill.Solid
.MarkerBackgroundColor = RGB(212, 142, rngColors(x))
.transparency = 0.5 <-Error: 'Object doesn't support this property or method.'
End With
Next
End Sub
编辑:感谢评论中的链接,以下代码在分配颜色后作为单独的宏运行时对我有用。不过这很棘手,我不知道为什么。首先我需要运行透明度代码(下),然后注释掉 .Solid,然后运行颜色代码(上),然后再次运行透明度代码(下),然后它就可以工作了。哎呀!我现在不太担心优化,但这似乎经常工作:
Sub transcheck()
' transcheck Macro
Dim cht As Chart
Dim Ser As Series
Dim lngIndex As Long
Dim lngChartType As XlChartType
Set cht = ActiveSheet.ChartObjects(1).Chart
Set Ser = cht.SeriesCollection(1)
lngChartType = Ser.ChartType
Ser.ChartType = xlColumnClustered
For lngIndex = 1 To 50
With Ser.Format.Fill
.Solid
.Visible = True
.transparency = 0.5
End With
Ser.ChartType = lngChartType
Next
End Sub