Microsoft Knowledge Base |
|
XL: Visual Basic Macro to Reverse Chart Series Order |
|
|
Last reviewed: July 8, 1997
Article ID: Q160528 |
|
The information in this article applies to:
SUMMARYThis article contains a Visual Basic for Applications macro example that demonstrates how to reverse the series order in a chart. For example, the macro allows you to plot the following data:
A1: Month B1: Series 1 C1: Series 2 A2: jan B2: 10 C2: 15 A3: feb B3: 20 C3: 25 A4: mar B4: 30 C4: 35 A5: apr B5: 40 C5: 45as if you typed the following data:
A1: Month B1: Series 2 C1: Series 1 A2: jan B2: 15 C2: 10 A3: feb B3: 25 C3: 20 A4: mar B4: 35 C4: 30 A5: apr B5: 45 C5: 40 MORE INFORMATIONMicrosoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft Product Support Services (PSS) Engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.
EXAMPLEThe sample macro in this article reverses the series order of column, bar, line, xy (scatter), or area charts. The example involves the following steps:
Typing Sample DataBefore you create the macro, type the following data in new worksheet:
A1: Month B1: Series 1 C1: Series 2 A2: jan B2: 10 C2: 15 A3: feb B3: 20 C3: 25 A4: mar B4: 30 C4: 35 A5: apr B5: 40 C5: 45 Creating the Chart and a Visual Basic ModuleMicrosoft Excel 97:
Creating the Macro
Sub ReversePlotOrder()
'Activate the chart.
ActiveChart.Parent.Activate
'Count the number of series.
x = ActiveChart.SeriesCollection.Count
'Loop through each series in the chart, reversing the plot order.
For i = 1 To ActiveChart.SeriesCollection.Count - 1
ActiveChart.ChartGroups(1).SeriesCollection(1).PlotOrder = x
x = x - 1
Next i
End Sub
|
|
Additional query words: 5.00 5.00a 5.00c 7.00 97
©1997 Microsoft Corporation. All rights reserved. Legal Notices. |