How to Dynamically Change Excel Chart Line Width from a Cell Value using VBA
Question details
The user wants to dynamically adjust the line thickness of a chart series in a spreadsheet based on a specific numerical value entered in a worksheet cell.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating chart formatting so that visual elements update instantly based on worksheet data inputs.
- Observed behavior
- Excel does not have a built-in formula feature to link chart line width to a cell value, requiring a VBA workaround.
Ensure you have saved your workbook as an Excel Macro-Enabled Workbook (.xlsm) and have enabled the Developer tab in your ribbon to access the VBA editor.
Use a VBA Macro to Update Chart Line Width
Create a VBA macro that reads a specified cell's value and applies it to the thickness property of a selected chart series.
Since standard spreadsheet functions do not support formatting properties inside charts, a VBA script is the most reliable way to link a cell value to a chart's line width. This script will identify the target chart, read the desired thickness from a cell, and apply it to the line.
Navigate to the Developer tab on the top ribbon and click 'Visual Basic', or simply press Alt + F11 on your keyboard.
In the VBA editor, right-click on your workbook name in the Project Explorer panel on the left, hover over 'Insert', and select 'Module'.
Type a macro that targets your chart and cell. For example: ActiveSheet.ChartObjects("Chart 1").Chart.FullSeriesCollection(1).Format.Line.Weight = ActiveSheet.Range("A1").Value
Close the VBA editor. You can run this macro from the Developer tab > Macros, or insert a Button (Form Control) on your worksheet and assign this macro to it for quick one-click updates.

Automate Chart Formatting with WPS Spreadsheet
WPS Spreadsheet offers robust charting tools and macro support, allowing you to create dynamic, professional charts with ease while maintaining full compatibility with Microsoft Excel files.
- 1. Open your workbook: Launch WPS Spreadsheet and open your macro-enabled workbook containing the chart.
- 2. Access the VBA Editor: Go to the 'Developer' tab and click on 'VBA Editor' to open the scripting environment.
- 3. Apply the formatting macro: Insert a module, paste your chart line width macro, and link it to a worksheet button.
- 4. Update your chart dynamically: Change the target cell value and click the assigned button to instantly update your chart's line width in WPS.

Frequently Asked Questions
Can I change chart line width dynamically without VBA?
No, Excel does not currently support linking chart formatting properties (like line width or colors) directly to a cell value using standard formulas. A VBA macro is required to bridge this gap.
How do I find the exact name of my chart for the VBA code?
Click on the chart in your worksheet to select it. Look at the Name Box located to the left of the formula bar at the top of the screen. You will see the chart's exact name, such as 'Chart 1' or 'Chart 2'.
Why isn't my VBA macro updating the chart line?
Ensure that the macro references the correct active sheet, chart name, and series index. Additionally, check that macros are enabled in your Trust Center settings and that the target cell contains a valid positive number for the line weight.
Will this macro run automatically when I change the cell value?
By default, standard macros require you to run them manually or via a button click. To make it automatic, you must place the VBA code inside a Worksheet_Change event in the specific sheet's VBA module, targeting the specific cell address.




