How to Automatically Position Excel Chart Data Labels for Positive and Negative Values
Question details
The user wants to automatically align chart data labels based on whether their values are positive or negative to eliminate tedious manual adjustments.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating multiple financial or comparative charts where data labels require dynamic positioning (above or below data points) based on their numeric value.
- Observed behavior
- Currently, placing data labels above positive values and below negative values requires manual adjustment for each point, which is highly inefficient for multiple charts.
Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled the Developer tab in your ribbon to access the VBA editor.
Use a VBA Macro to Conditionally Position Data Labels
Applying a VBA macro is the most efficient way to loop through chart series and assign label placements dynamically based on numeric values.
This macro iterates through every data point in a specified chart. It checks if the label is numeric, and then applies xlLabelPositionBelow for negative numbers and xlLabelPositionAbove for positive numbers.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
Click 'Insert' > 'Module' from the top menu. Paste the provided macro code: Sub AdjustDataLabels() ... Set cht = ActiveSheet.ChartObjects(1) ... Next ser End Sub.
Return to your worksheet. Click on your chart, click the Chart Elements (+) button, and check 'Data Labels'. The macro requires data labels to be visible before it can move them.
Go back to the VBA editor, click anywhere inside your code, and press F5 to run it. Your data labels will instantly snap to their correct positions.

Fix Worksheet and Chart Reference Errors
If the macro fails to execute or cannot find the chart, it usually means the code is referencing the wrong worksheet.
Easily Manage Charts and Macros in WPS Spreadsheet
WPS Spreadsheet offers powerful chart formatting capabilities and full support for VBA macros, allowing you to easily automate data label positioning just as you would in Microsoft Excel.
- 1. Open Your Workbook: Launch WPS Spreadsheet and open your macro-enabled workbook.
- 2. Access the Macro Editor: Navigate to the Tools or Developer tab and click on 'Macro' or 'Visual Basic Editor'.
- 3. Run the Data Label Script: Insert the same VBA code to instantly automate the positioning of your positive and negative data labels.

Frequently Asked Questions
Can I automatically position data labels without using VBA?
Currently, Excel does not have a built-in toggle to automatically split data label positions based on positive or negative values. You must either manually drag the labels or use a VBA macro to automate the physical placement.
Why am I getting a 'Chart name not recognized' error in VBA?
This error typically occurs if the macro is attempting to modify the 'ActiveSheet', but the chart you want to target is located on a different worksheet. Update your code to explicitly call the correct worksheet by its name, such as Worksheets("Dashboard").ChartObjects(1).
Do I need to turn on data labels before running the macro?
Yes. The VBA script checks the '.HasDataLabels' property before attempting to reposition them. You must first add standard data labels to your chart series through the Excel ribbon before executing the macro.




