我有一个宏,可以绘制特定批次的测试结果。我的测试结果提供了两个数据集,它们在数值上有很大的不同,因此我需要将其绘制到主要和次要y轴上。
我的问题是我希望相同批次的颜色相同。
下面的代码可用于绘制数据,但我想将它们组合起来,因此名称一经提及且颜色相同。
有可能吗?
最佳问候 朗尼
With ActiveChart
I = 1
Do Until I = TestNr + 1
.SeriesCollection.NewSeries
.SeriesCollection(I + 4).Name = Sheets("Data").Range("A" & 11 + I)
.SeriesCollection(I + 4).XValues = Sheets("Data").Range("B4:P4")
.SeriesCollection(I + 4).Values = Sheets("Data").Range("B" & 11 + I & ":P" & 11 + I)
ActiveChart.SeriesCollection(I + 4).Select
With Selection
.Border.LineStyle = xlContinuous
.Border.Weight = xlThin
End With
ActiveChart.FullSeriesCollection(I + 4).AxisGroup = 1
I = I + 1
Loop
End With
With ActiveChart
J = 1
Do Until J = TestNr + 1
.SeriesCollection.NewSeries
.SeriesCollection(J + 4 + TestNr).Name = Sheets("Data").Range("A" & 11 + J)
.SeriesCollection(J + 4 + TestNr).XValues = Sheets("Data").Range("B4:P4")
.SeriesCollection(J + 4 + TestNr).Values = Sheets("Data").Range("R" & 11 + J & ":AF" & 11 + J)
ActiveChart.SeriesCollection(J + 4 + TestNr).Select
With Selection
.Border.LineStyle = xlContinuous
.Border.Weight = xlThin
End With
ActiveChart.FullSeriesCollection(J + 4 + TestNr).AxisGroup = 2
J = J + 1
Loop
End With
答案 0 :(得分:0)
我找到了解决上述问题的方法,并想将其发布,以防其他人遇到相同的问题。可能不是最漂亮的解决方案,但是它可以正常工作。
Dim r As Byte, g As Byte, b As Byte
Dim K As Variant
With ActiveChart
K = 1
Do Until K = TestNr + 1
r = WorksheetFunction.RandBetween(0, 255)
g = WorksheetFunction.RandBetween(0, 255)
b = WorksheetFunction.RandBetween(0, 255)
ActiveChart.SeriesCollection(4 + K).Select
With Selection
.Border.Color = RGB(r, g, b)
.MarkerBackgroundColor = RGB(r, g, b)
.MarkerForegroundColor = RGB(r, g, b)
End With
ActiveChart.SeriesCollection(4 + K + TestNr).Select
With Selection
.Border.Color = RGB(r, g, b)
.MarkerBackgroundColor = RGB(r, g, b)
.MarkerForegroundColor = RGB(r, g, b)
End With
K = K + 1
Loop
End With