简体   繁体   中英

Sorting A Graph Using VBA

I have an excel macro which updates a graph to represent data on another tab. I also want to sort the graph. I can't seem to manually do this and just record the macro.

I have tried the below code, but get a run time error 424 saying Object Required

Sub Productivity_Report_Graph()

ActiveSheet.ChartObjects("Chart 1").Activate

ActiveChart.FullSeriesCollection(1).Values = _
    "='Customer Service Report'!$D$2:$D$100"

ActiveChart.FullSeriesCollection(2).Values = _
    "='Customer Service Report'!$P$2:$P$100"

ActiveChart.FullSeriesCollection(3).Values = _
    "='Customer Service Report'!$Q$2:$Q$100"

ActiveChart.FullSeriesCollection(1).XValues = _
    "='Customer Service Report'!$B$2:$B$100"

ActiveChart.FullSeriesCollection(1).XValues.AutoSort _

End Sub

I ended up copying my data to another tab, reordering the date here (this updated on the graph instantly) and then hiding the graph. I did this as part of a larger RPA process but this could be done in an excel macro also.

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