logo
search
VBA & Macro Problems

How to Fix Missing Category Names in Excel Doughnut Chart VBA Labels

Muhammad TalhaMuhammad Talha Oct 9, 2026 869 views

Question details

The user needs to resolve an issue where Excel VBA fails to correctly populate category names in doughnut chart data labels, leaving only a separator like a colon and a space.

How to Fix Missing Category Names in Excel Doughnut Chart VBA Labels
Product
Microsoft Excel
Device & OS
not provided
Scenario
Generating or updating a doughnut chart's data labels using a VBA macro.
Observed behavior
The VBA script adds only a colon and space to the data labels instead of the actual category names, because the chart's CategoryNames collection does not return the expected text values.
Before you start

Verify that your chart is pointing to the correct data range in your worksheet and ensure your workbook is saved in a macro-enabled format (.xlsm) before editing the VBA code.

Solution 1Recommended

Read Category Names Directly from the Worksheet Range

Bypass the unreliable CategoryNames collection by fetching the text directly from the source cells in your worksheet.

When the chart's CategoryNames collection fails to return the expected values in VBA, the most reliable workaround is to extract the category name directly from the worksheet cells containing your data.

This method ensures accuracy regardless of how the chart interprets the data range, allowing you to manually construct the perfect data label string.

1
Open the VBA Editor

Press ALT + F11 to open the Visual Basic for Applications (VBA) editor and locate the module containing your chart macro.

2
Identify the source data location

Determine the exact worksheet range, including the row numbers and column index, where your chart's category names are stored (e.g., column A).

3
Modify your VBA loop

Update your VBA code to iterate through the data points of the doughnut chart series using a For loop.

4
Extract and apply the cell value

Use the code `categoryName = ws.Cells(rowNumber, categoryColumn).Value` to read the specific category name. Then, set the label text: `point.DataLabel.Text = categoryName & ": " & pointValue`.

Read Category Names Directly from the Worksheet Range
Version Compatibility: Verify that your specific version of Excel allows the DataLabel.Text property to be explicitly set via VBA, as older versions may have limited support for this object.
Free Microsoft Office alternative

Use WPS Office for Reliable Spreadsheet Management and Macros

If you frequently encounter VBA charting limitations in Microsoft Excel, consider switching to WPS Office. It offers a lightweight, highly compatible alternative with excellent support for VBA macros and complex spreadsheet charting, without the hefty subscription fees.

  1. 1. Download and Install: Visit the official WPS Office website to download and install the free suite on your device.
  2. 2. Open Your Workbook: Launch WPS Spreadsheets and open your .xlsm file containing the doughnut chart and VBA code.
  3. 3. Run Your Macros: Enable macros when prompted and execute your VBA scripts to generate charts smoothly.
Free and lightweight Office suiteHigh compatibility with Microsoft Excel (.xlsx, .xlsm, .xls) formatsNative support for VBA macros and complex charting featuresFamiliar user interface for seamless migration
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Excel VBA chart label only show a colon?

This typically occurs when your macro concatenates the category name and the value (e.g., separating them with a colon), but the chart's CategoryNames collection fails to recognize the labels, returning an empty string or null for the category name portion.

Can I format individual data labels in a VBA doughnut chart?

Yes. You can iterate through the Points collection of a Series in VBA and access the DataLabel object for each specific point. This allows you to customize its font, color, formatting, and custom text.

How do I reference a specific cell value for a chart label in VBA?

You can use the Cells property in conjunction with the worksheet object, such as `Worksheets("Sheet1").Cells(row, column).Value`, to retrieve the exact text from a cell and assign it directly to the DataLabel.Text property.