Can graph formatting be linked to source data formatting?

engkinooi

New Member
Joined
Dec 25, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Is there a way to link the formatting of a graph to the formatting of the source data? For example, if I make a bar chart out of numerical data, can Excel link the color of each bar to match the font color of the source data? And if I change the font color of one particular data point, Excel automatically changes the color of the corresponding bar.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
This can be done only with VBA. Even with VBA it is rather complicated because VBA cannot automatically a format change to cell, such as a font color change. You could add a button that does the updates on user demand. The actual code would be very specific to your chart and your data, so I can't offer a general solution.
 
Upvote 0
As Jeff ( @6StringJazzer ) points out, Excel can’t detect a change in font colour, and only VBA will achieve the connection between series value font & chart series font you seem to be seeking. A lot depends on how & why your data values change.

I’ve offered some options below. The first (Demo 1) shows how you can have 2 series on a chart of different colours – and the bar value will change depending on which series the value sits in on the source data (determined by an IF function). Change (for example) January’s figure in cell F2 on the Demo file from 11 to 5 and see what happens with the bar colour for January.

Your requirement seems more complicated. Whereas you can’t trigger an event by a change in font colour – you can run some code if a value changes on a sheet. In the demo file, I’ve used a Worksheet_Change event to run the code that changes the bar colours in the second chart to whatever the font of the value in the source data is. To demonstrate, change the font colour in cell I2 (January’s value) to red – then either change the source value in cell F2 or, to use Jeff’s suggestion, run the code independently (in the demo file by pressing the button).

Data layout:
Chart Demos.xlsm
ABCDEFGHIJKLMNOPQRST
1Month<10=>10MonthAmountMonthJanFebMarAprMayJunJulAugSepOctNovDec
2Jan 11Jan11Jan11
3Feb 10Feb10Feb10
4Mar9 Mar9Mar9
5Apr9 Apr9Apr9
6May 11May11May11
7Jun 12Jun12Jun12
8Jul 15Jul15Jul15
9Aug4 Aug4Aug4
10Sep5 Sep5Sep5
11Oct6 Oct6Oct6
12Nov 11Nov11Nov11
13Dec5 Dec5Dec5
Sheet1
Cell Formulas
RangeFormula
B2:B13B2=IF(F2<10,F2,"")
C2:C13C2=IF(F2>=10,F2,"")
I2I2=F2
J3J3=F3
K4K4=F4
L5L5=F5
M6M6=F6
N7N7=F7
O8O8=F8
P9P9=F9
Q10Q10=F10
R11R11=F11
S12S12=F12
T13T13=F13


VBA - put in a standard module:
VBA Code:
Option Explicit
Sub Change_Color()
    Dim x As Long, s As String, c As Range
    ActiveSheet.ChartObjects("Chart 2").Select  '<~~ change to actual chart name
    For Each c In Range("I2:T13")               '<~~ demonstration range used
        If c <> "" Then                         '<~~ IF there is a value in the cell for this range, then...
            x = c.Characters.Font.Color         '<~~ gets the font colour
            s = Cells(c.Row, 8).Value           '<~~ gets the name of the series from column H
                ActiveChart.SeriesCollection(s).Interior.Color = x
        End If
    Next c
    [A1].Select
End Sub

VBA - put in the worksheet module of the sheet with the data & charts (right click the tab name, select View Code, paste code into the empty module that appears)
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Change_Color
End Sub



Link to demo file: Chart Demos.xlsm
 
Upvote 0

Forum statistics

Threads
1,225,231
Messages
6,183,751
Members
453,188
Latest member
amenbakr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top