Updating Charts with VBA

Updating Charts Using VBA Code

Several customers have asked for the ability to update the SPC for Excel charts using VBA alone.   They did not want to go through the input box that asks for which charts to update.  With build 4.0.1.3, this is now possible with the following types of charts created by SPC for Excel:

  • Pareto diagrams
  • Histograms
  • Attribute Control Charts
  • Variable Control Charts
  • Process Capability Charts
  • Scatter Diagrams
  • Waterfall Charts

To use this option, create the chart initially in an Excel workbook.  Once the chart is created, you can use the code below to call the update function.  The program will find the new data and update the chart based on the options you have selected.  You can still change those options by selecting the "Options" icon from the SPC toolbar or menu.

VBA Code

In the code below, replace "chartname" with the name of the worksheet tab containing the chart.

Pareto Diagrams
Application.Run "spcforexcelv4.xla!UpdateParetoBPI", "chartname"

Histograms
Application.Run "spcforexcelv4.xla!UpdateHistogramBPI", "chartname"

Attribute Control Charts (p, np, c and u)
Application.Run "spcforexcelv4.xla!UpdateAttributeChartBPI", "chartname"

Variable Control Charts (Xbar-R, Xbar-s, X-mR, Xbar-R-R, Xbar-R-s, Run)
Application.Run "spcforexcelv4.xla!UpdateVariableChartBPI", "chartname"

Process Capability
Application.Run "spcforexcelv4.xla!UpdateProcessCapabilityBPI", "chartname"

Scatter Diagrams
Application.Run "spcforexcelv4.xla!UpdateScatterBPI", "chartname"

Waterfall Charts
Application.Run "spcforexcelv4.xla!UpdateWaterfallBPI", "chartname"