基于数据标签文本的颜色数据点 – Excel VBA

在这里输入图像说明 我有下面的代码基于数据标签文本的颜色气泡图数据点。 我不知道为什么我保持“无效的参数错误”

编辑更清晰。

代码通过电子表格进行循环,在那里存储数据标签过滤条件(请参阅附图)。 它会复制一个预先制作的气泡图并给它着色。 variablesa和c之间的variablesf循环,并基于这两个variables之间的值,气泡图将匹配时显示颜色。 如果不是,它会移过去。 气泡着色之后,它将进入下一个着色的变化。

Sub Slide31() Dim rngx As Range Dim rngy As Range Dim rngz As Range Dim ws3 As Worksheet Dim ws As Worksheet Dim ws1 As Worksheet Dim ws2 As Worksheet Dim icnt As Long Dim lastrow As Long Dim k As Long Dim icounter As Long Dim a As Long Dim c As Long Dim b As Long Dim d As Variant Dim Chart As ChartObject Dim PPapp As Object Dim PPTDoc As PowerPoint.Presentation Dim PPT As PowerPoint.Application Dim PPpres As Object Dim pptSlide As PowerPoint.Slide Dim ppslide As Object Dim e As Long Dim f As Long Dim filename As String Dim filename2 As String Dim x As Variant Dim y As Variant Dim z As Variant Dim ch As Chart Dim s As Series Dim iPoint As Long Dim nPoint As Long Set ws = Worksheets("Reference") Set ws1 = Worksheets("Bubbles") Set ws2 = Worksheets("Slide 31") Set ws3 = Worksheets("Bubble Reference") ws2.Activate 'ws2.Range("h:h").NumberFormat = "0.00%" lastrow = ws2.Cells(Rows.Count, "b").End(xlUp).Row For icounter = 1 To lastrow For icnt = 51 To 79 If ws2.Cells(icounter, 2) = ws.Cells(icnt, 3) Then d = ws.Cells(icnt, 3) a = icounter + 2 b = icounter + 2 c = icounter + 11 filename = "" filename2 = "" ws3.ChartObjects(1).Copy ws2.Paste Set ch = ActiveChart Set s = ch.SeriesCollection(1) For f = a To c nPoint = s.Points.Count For iPoint = 1 To nPoint If ws2.Cells(f, 8) = s.Points(iPoint).DataLabel.Text Then s.Points(iPoint).Format.Fill.ForeColor.RGB = RGB(192, 0, 0) End If Next iPoint Next f End If Next icnt Next icounter 

Point对象没有Interior属性。 (编辑:是的,即使Dox和Intellisense似乎没有暴露它)。

( 点对象引用 | Excel参考 )

你得到的具体错误(1004,“无效的参数错误”)类似于索引出界,你不知何故试图以无效的方式索引点集合,但我不知道这是如何可能的。 例如,如果您尝试使用s.Points(0)s.Points(s.Points.Count+1) ,则可以轻松获得此错误。

你可以尝试这种替代方法:

 Dim pt as Point For Each pt in s.Points If ws2.Cells(f, 8) = pt.DataLabel.Text Then pt.Format.Fill.ForeColor.RGB = RGB(192, 0, 0) End If Next