Excel Reference

Change the Color of the Horizontal Axis of a Sparkline

You can change the color of the horizontal axis of a sparkline by using the Color property of the SparkColor object. The following code example iterates through three sparkline groups and sets the color of the horizontal axis equal to the fill color in cell A8. This example requires three sparkline groups starting in cells A2, B2, and C2. Cell A8 must be filled with the color that you want to use for the color of the horizontal axis. This example uses Color property of the Interior.md) object to get the color of cell A8.

vb Sub AxisColor() 'The sparkline group Dim oSparkGroup As SparklineGroup 'Loop through the sparkline groups on the sheet For Each oSparkGroup In Range("A2:C2").SparklineGroups 'Show the axis oSparkGroup.Axes.Horizontal.Axis.Visible = True 'Set the color of the axis to the color of cell A8 oSparkGroup.Axes.Horizontal.Axis.Color.Color = Range("A8").Interior.Color Next oSparkGroup End Sub

See also

  • SparklineGroup Object
  • Programming With Sparklines In Excel

!include[Support and feedback]

6 community Q&A using Change the Color of the Horizontal Axis of a Sparkline

Libraries that work with Change (5)

169 words1 sectionsMicrosoft Docs rev. 06/08/2017