How to Automatically Change Excel Chart Colors Based on Dates
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.

- 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.
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.
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.
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.
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.
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
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.
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. Open your dataset in WPS Spreadsheet: Launch WPS Office and open your .xlsx file containing the dates and values.
- 2. Apply standard formatting: Highlight your data and go to the Home tab to apply Conditional Formatting based on your specific date rules.
- 3. Insert your chart: Select the data range, navigate to the Insert tab, and choose your preferred Chart type (e.g., Column Chart).
- 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.

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.




