![](/img/trans.png)
[英]Excel VBA - Reference chart data point by name instead of index number
[英]VBA Excel Pivot Chart Data Point Marker based on Category Name
我有一个通过SQL查询填充的Excel中的数据表。
该表是数据透视表的数据源,数据透视表又用于创建数据透视图。
我需要以一种颜色显示直到本月(例如,2016年7月)的数据,并以另一种颜色显示未来的数据。 我做了研究,看来我必须操纵源数据来这样做(这意味着应该更改SQL查询的结果)。 就我而言,这是不可能的。
因此,我决定突出显示“今天”数据点以显示过去和将来的交汇处。 如何使用VBA做到这一点? 我需要以下逻辑:
for i=1 to category.count
if categoryname(i)="July-2016" then change marker style
end if
next
谢谢。
我使用简单的Excel公式确定当月的数据点索引,然后通过宏循环从项目开始到当月更改了行颜色:
For i = 1 To DataPointIndex
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Points(i).Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
.DashStyle = msoLineSolid
End With
使用标记可以完成类似的操作,但是我更喜欢使用不同的线条颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.