简体   繁体   中英

VBA Excel Pivot Chart Data Point Marker based on Category Name

I have a data table in Excel that is populated through SQL query.

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. 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). 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? 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 :

        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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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