简体   繁体   English

基于类别名称的VBA Excel数据透视图数据点标记

[英]VBA Excel Pivot Chart Data Point Marker based on Category Name

I have a data table in Excel that is populated through SQL query. 我有一个通过SQL查询填充的Excel中的数据表。

This table is a data source for the pivot table, which in its turn used to created a pivot chart. 该表是数据透视表的数据源,数据透视表又用于创建数据透视图。

I need to show data till this month (eg July-2016) in one colour and future in another. 我需要以一种颜色显示直到本月(例如,2016年7月)的数据,并以另一种颜色显示未来的数据。 I did my research and it appears that I have to manipulate source data to do so (meaning the results of the SQL query should be changed). 我做了研究,看来我必须操纵源数据来这样做(这意味着应该更改SQL查询的结果)。 It is not possible in my case. 就我而言,这是不可能的。

So I decided to highlight "Today" data point to show where past and future meet. 因此,我决定突出显示“今天”数据点以显示过去和将来的交汇处。 How can I do it using VBA? 如何使用VBA做到这一点? I need something with this logic: 我需要以下逻辑:

for i=1 to category.count
if categoryname(i)="July-2016" then change marker style
end if
next

Thank you. 谢谢。

I have used simple Excel formulas to determine the data point index of current month and then changed line colour through macro looping from the start of the project to current month : 我使用简单的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

Similar could be done with marker, but I prefer different line colour. 使用标记可以完成类似的操作,但是我更喜欢使用不同的线条颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM