VBA & Macro Problems

How to Plot VBA Arrays Directly in Excel Charts

Huda QurayshiHuda Qurayshi Oct 26, 2026 868 views

Question details

The user wants to create Excel chart series using VBA arrays directly, bypassing the need to output array data into worksheet cells.

How to Plot VBA Arrays Directly in an Excel Chart
Product
Excel, WPS Spreadsheet
Device & OS
not provided
Scenario
Creating dynamic charts using VBA macros where data is stored in memory arrays rather than in worksheet ranges.
Observed behavior
The goal is to successfully assign VBA arrays directly to the XValues and Values properties of a chart series.
Before you start

Ensure that your VBA arrays are properly populated and that the arrays intended for the X and Y axes have matching lengths and compatible bounds.

Solution 1Recommended

Assign Arrays Directly to Chart Series Properties

Use VBA to create a chart, clear default series, and assign your in-memory arrays directly to the chart's XValues and Values properties.

By directly passing arrays to the chart series object, you can keep your spreadsheet clean and improve the performance of your macros by avoiding unnecessary read/write operations to the worksheet.

1
Create a new chart object

Use the Charts.Add or Shapes.AddChart method in your VBA script to instantiate a new chart in your active worksheet.

2
Remove default series

Loop through the chart's SeriesCollection and delete any existing auto-generated series to ensure you are starting with a blank canvas.

3
Add a new series

Use the SeriesCollection.NewSeries method to create a data series for your first set of array values.

4
Assign the X and Y arrays

Set your category axis array by assigning it to the XValues property (e.g., s.XValues = UX) and set your value axis array by assigning it to the Values property (e.g., s.Values = UY).

5
Add additional series if needed

Repeat the NewSeries process to add a second series. Assign another array (e.g., s2.Values = yp) while using the same XValues array to plot multiple lines on the same chart.

Assign Arrays Directly to Chart Series Properties
Array Size Limits: Keep in mind that there is a character limit for the underlying formula string generated when passing arrays directly to a chart. Extremely large arrays may exceed this limit and will require outputting the data to a hidden worksheet range instead.
Advanced VBA Support in WPS

Create and Manage VBA Charts with WPS Spreadsheet

WPS Spreadsheet offers robust VBA and Macro support, allowing you to easily run advanced scripts to plot memory arrays directly into dynamic charts.

  1. 1. Access the VBA Editor: Open WPS Spreadsheet and navigate to the Developer tab to launch the VBA Editor.
  2. 2. Write your array macro: Insert a new Module and write your macro to populate your UX and UY arrays with data.
  3. 3. Assign arrays to the chart: Use standard VBA charting methods to assign your populated arrays to the SeriesCollection.Values and XValues properties.
  4. 4. Run the script: Execute the macro to instantly generate your chart directly from memory, without modifying any cell data.
Fully compatible with Microsoft Excel VBA macros and chart objects.Lightweight and fast execution for heavy data processing scripts.Intuitive Developer tab for easy macro recording and script editing.Free alternative with comprehensive spreadsheet modeling tools.
microsoft office alternative - wps office

Frequently Asked Questions

Why am I getting a 'Type Mismatch' error when assigning arrays to a chart?

This usually happens if the array is not formatted properly or if it is multidimensional. Ensure your arrays are 1D arrays before assigning them to the XValues or Values properties.

Is there a limit to how many data points I can plot directly from a VBA array?

Yes, charting engines have a limitation on the string length of the SERIES formula. If your array contains too many data points, the formula length may exceed the limit (usually around 8192 characters), causing a runtime error.

Can I plot a 2D array directly to a chart series?

No, the XValues and Values properties expect a 1D array. If you have a 2D array, you must first extract the desired column or row into a separate 1D array before assigning it to the chart.

How do I format the chart lines and markers using VBA?

After assigning the arrays to your series, you can modify the Format.Line and MarkerStyle properties of the Series object directly within your VBA script to customize colors and shapes.