我一直在努力工作无数个小时而无法继续。任何帮助都非常感谢!
我正在尝试创建可以循环创建大约55个图形的宏。我在使用命名范围时遇到困难,而且我相信(直到这里的大师证明不是这样),命名范围才是最佳选择。
我绝对不会这样做(我将添加一个循环函数)但是为了说明的目的,3个范围(以及我希望在同一图表上绘制的3行)如下所示:
Set rng1 = Union(Cells(SA_Row, 11), Cells(SA_Row, 42), Cells(SA_Row, 72), Cells(SA_Row, 122))
Set rng2 = Union(Cells(SA_Row, 11), Cells(SA_Row, 43), Cells(SA_Row, 73), Cells(SA_Row, 123))
Set rng3 = Union(Cells(SA_Row, 11), Cells(SA_Row, 44), Cells(SA_Row, 74), Cells(SA_Row, 124))
因此,所有3条线将具有相同的起始值,但随后在该范围内的不同单个单元之间存在大量间隔。原因是这代表了不同年份的目标(例如,2020,2030,2040等)到目前为止,我主要完成了格式化参数,但我将添加“Count = X to Y ... Select case等”。这是一个好的方法吗?无论如何,到目前为止我写的代码看起来像:
Set cht = Worksheets("Graphs").ChartObjects.Add(Top:=Graph_Position, Left:=910, Width:=160, Height:=75)
Set rng1 = Union(Cells(SA_Row, 11), Cells(SA_Row, 42), Cells(SA_Row, 72), Cells(SA_Row, 122))
Set rng2 = Union(Cells(SA_Row, 11), Cells(SA_Row, 43), Cells(SA_Row, 73), Cells(SA_Row, 123))
Set rng3 = Union(Cells(SA_Row, 11), Cells(SA_Row, 44), Cells(SA_Row, 74), Cells(SA_Row, 124))
With cht.Chart
.ChartType = xlLineMarkers
.HasLegend = False
.HasAxis(xlCategory) = False
.ChartArea.Border.LineStyle = xlNone
.Axes(xlValue, xlPrimary).TickLabels.Font.Name = "VWAG TheSans"
With .Axes(xlValue)
.MaximumScale = 1
.MajorUnit = 0.2
.Format.Line.Visible = msoFalse
.MajorGridlines.Format.Line.Weight = 0.35
.MajorGridlines.Format.Line.ForeColor.RGB = RGB(217, 217, 217)
.TickLabels.Font.Size = 4
.TickLabels.NumberFormat = "0%"
End With
'Set rngSource = Range(rng1, rng2, rng3)
'.SetSourceData rngSource
' .SeriesCollection.NewSeries.Values = Range("rng1")
' .SeriesCollection.NewSeries.Values = Range("rng2")
' .SeriesCollection.NewSeries.Values = Range("rng3")
With .FullSeriesCollection(1)
.Format.Line.ForeColor.RGB = RGB(5, 204, 216)
.MarkerStyle = 8
.MarkerSize = 3
.Format.Fill.ForeColor.RGB = RGB(5, 204, 216)
.Format.Line.Weight = 1
End With
With .FullSeriesCollection(2)
.Format.Line.ForeColor.RGB = RGB(192, 10, 0)
.MarkerStyle = 8
.MarkerSize = 3
.Format.Fill.ForeColor.RGB = RGB(192, 10, 0)
.Format.Line.Weight = 1
End With
With .FullSeriesCollection(3)
.Format.Line.ForeColor.RGB = RGB(50, 200, 59)
.MarkerStyle = 8
.MarkerSize = 3
.Format.Fill.ForeColor.RGB = RGB(50, 200, 59)
.Format.Line.Weight = 1
End With
End With
"'"
只是我玩弄不同的尝试。到目前为止,我在图表上没有数据,或者只有1行而不是3行。请帮忙!
我相信我可能通过以下方式解决了这个问题:
cht.Chart.SeriesCollection.Add Source:=rng1
cht.Chart.SeriesCollection.Add Source:=rng2
cht.Chart.SeriesCollection.Add Source:=rng3
你们有什么感想?