VBA & Macro Problems

Set Precise Microsoft Excel Chart Positions and Sizes with VBA

Elise WilliamsElise Williams Nov 13, 2026 869 views

Question details

The user wants to position and resize Excel charts and chart components precisely with VBA, including controlling the vertical axis length.

Set Precise Microsoft Excel Chart Positions and Sizes with VBA
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
Arrange embedded charts on a worksheet and keep the plotting region a consistent size whether the horizontal axis is displayed or hidden.
Observed behavior
Chart objects and plot areas expose positioning and sizing properties, but assigning a value to Axis.Height does not work because the property is read-only.
Before you start

Open the workbook in desktop Excel with VBA available, and identify the worksheet and embedded chart name you want to modify. VBA chart dimensions use points, not pixels; replace the worksheet and chart names in the examples with your own.

Solution 1Recommended

Set the embedded chart's worksheet position and size

Use ChartObject properties to control the outer chart container independently of the components inside it.

For an embedded chart, Left and Top locate its container relative to the worksheet. Width and Height set the container dimensions. These values do not directly specify the size of the inner plotting region.

1
Open a VBA module

In Excel, open Developer > Visual Basic. In the VBA editor, select your workbook and choose Insert > Module.

2
Set the chart container dimensions

Paste this macro into the module, replacing Sheet1 and Chart 1 with your worksheet and chart names: Sub PositionChart() Dim co As ChartObject Set co = ThisWorkbook.Worksheets("Sheet1").ChartObjects("Chart 1") With co .Left = 72 .Top = 36 .Width = 432 .Height = 288 End With End Sub The example places a 6-by-4-inch chart 1 inch from the worksheet's left edge and 0.5 inch from its top edge.

3
Run and inspect the chart

Place the cursor inside PositionChart and choose Run > Run Sub/UserForm in the VBA editor. Return to the worksheet and inspect the chart's placement.

Set the embedded chart's worksheet position and size
Align a chart to a cell: To anchor the chart position to a cell, use .Left = co.Parent.Range("B2").Left and .Top = co.Parent.Range("B2").Top inside the With co block.
Free Microsoft Office alternative

Use WPS Spreadsheet for Everyday Chart Editing

WPS Office is a free, lightweight alternative for everyday spreadsheet and chart work, with Excel-format compatibility and a familiar interface that makes migration straightforward. It does not fix Excel's read-only Axis.Height property; verify VBA support in your WPS edition before relying on chart-positioning macros.

Create and edit spreadsheet charts through a familiar interface.Open and save Microsoft Excel .xlsx and .xls files.Use a lightweight, free Office suite for routine spreadsheet work.Move existing Excel workbooks into a familiar workflow, while checking specialized chart layouts and macros.
microsoft office alternative - wps office

Frequently Asked Questions

Are Excel VBA chart dimensions measured in pixels?

No. Chart positioning and sizing properties use points, with 72 points equal to 1 inch. For example, set ChartObject.Width to 432 for a 6-inch-wide chart.

Why does assigning Axis.Height fail?

Axis.Height is read-only, so VBA cannot assign a value to it. Press F2 in the VBA editor and look up Axis > Height to inspect it. For a standard two-dimensional chart, adjust PlotArea.InsideHeight to control the vertical plotting span.

What is the difference between ChartObject.Left and PlotArea.Left?

ChartObject.Left positions the embedded chart container relative to the worksheet's left edge. PlotArea.Left positions the plot area relative to the chart's left edge. They use different coordinate origins.

How can I keep the plotting height consistent when hiding the horizontal axis?

Apply the horizontal-axis visibility change first, then set Chart.PlotArea.InsideHeight to your target value. Keep the outer chart large enough for the remaining labels and verify the resulting height, because Excel can recalculate layout after chart changes.

Can I use these ChartObject examples on a chart sheet?

Not directly. These examples target embedded charts through Worksheet.ChartObjects. For a chart sheet, access its Chart object through ThisWorkbook.Charts("ChartSheetName"); the worksheet-positioning code for the embedded container does not apply.