Chart & Visualization Issues

How to Automatically Change Excel Chart Colors Based on Dates

Phi Hung VoPhi Hung Vo Nov 2, 2026 870 views

Question details

The user needs to dynamically change the colors of points or columns in an Excel chart based on specific date criteria, such as separating past/completed months from future/forecast months.

How to Automatically Change Excel Chart Colors Based on Dates
Product
Excel
Device & OS
not provided
Scenario
Updating a single-series column chart as the year progresses to differentiate past and future months visually.
Observed behavior
Conditional formatting applies successfully to the worksheet cells based on the date, but does not automatically reflect in the corresponding chart points without manual adjustment.
Before you start

Ensure your worksheet data is set up with conditional formatting rules applied to the cells representing the chart's data values. Also, verify that the Developer tab is enabled in your ribbon so you can access the VBA editor.

Solution 1Recommended

Use a VBA Macro to Link Chart Colors to Cell Conditional Formatting

By using a VBA script, you can extract the DisplayFormat color applied by conditional formatting in your worksheet and apply it directly to your chart's data points.

Standard Excel charts do not natively link to the conditional formatting applied to their source cells. However, by leveraging the DisplayFormat property in VBA, we can detect the actual color displayed on a cell and dynamically update the corresponding chart column to match.

1
Apply conditional formatting to your data range

Select the cells containing your chart values. Go to the Home tab, click Conditional Formatting, and create rules based on your date criteria to color past months differently from forecast months.

2
Open the VBA Editor

Press ALT + F11 to open the Visual Basic for Applications window. Click on 'Insert' in the top menu and select 'Module' to create a new script area.

3
Paste the macro code

In the new module window, paste the following code: Sub ColorChartColumns() Dim YAddress As Variant, S As Variant, I As Long Dim FCI As Long, FCICond As Long Set S = Selection Set YAddress = Range(Split(Split(S.Formula, ",")(2), "!")(1)) For I = 1 To S.Points.Count FCI = YAddress.Cells(I).Interior.ColorIndex FCICond = YAddress.Cells(I).DisplayFormat.Interior.ColorIndex If FCICond <> FCI Then FCI = FCICond S.Points(I).Interior.ColorIndex = FCI Next I End Sub

4
Run the macro on your chart

Return to your worksheet and click exactly on the specific data series within your chart to select it. Press ALT + F8, choose the 'ColorChartColumns' macro, and click Run. The chart points will now immediately match your cell colors.

Macro Re-execution: This macro runs on demand. You will need to select the series and run the macro again whenever the conditional formatting changes due to passing dates or data updates.

Create and Manage Dynamic Charts Effortlessly in WPS Spreadsheet

WPS Spreadsheet provides robust chart formatting options and comprehensive support for advanced functions, allowing you to seamlessly manage your data visualizations. Its built-in tools help you effectively present your data with extensive formatting capabilities.

  1. 1. Open your dataset in WPS Spreadsheet: Launch WPS Office and open your .xlsx file containing the dates and values.
  2. 2. Apply standard formatting: Highlight your data and go to the Home tab to apply Conditional Formatting based on your specific date rules.
  3. 3. Insert your chart: Select the data range, navigate to the Insert tab, and choose your preferred Chart type (e.g., Column Chart).
  4. 4. Customize data points manually: If you prefer not to use macros, you can customize individual data points by double-clicking a specific column in the chart and adjusting the fill color in the right-hand formatting pane.
Fully compatible with Microsoft Excel file formats (.xlsx) and chart objects.Intuitive interface for applying conditional formatting and customizing chart styles.Lightweight and runs smoothly, ensuring efficient processing of large datasets.Supports powerful developer tools and VBA macros for extensive automation.
microsoft office alternative - wps office

Frequently Asked Questions

Can I conditionally format an Excel chart natively without using VBA?

Currently, native Excel and WPS Spreadsheet do not support dynamic conditional formatting directly inside charts. To change chart colors based on rules, you must either manually color the data points, separate the data into multiple series, or use a VBA macro to read the cell formatting automatically.

Why isn't my macro automatically updating the chart colors when the date changes?

The provided VBA macro runs on demand. If the date shifts and changes the worksheet cell color, the chart will not update automatically. You must manually run the macro again (ALT + F8) or link the macro to a Worksheet_Calculate event in VBA to trigger it whenever the sheet recalculates.

Does the DisplayFormat property work in custom functions (UDFs)?

No, the DisplayFormat property cannot be used in User Defined Functions called directly from worksheet cells; it will return an error. It can only be utilized in subroutines (macros) triggered via buttons, shortcuts, or worksheet events.