Macro to change colour on selected series on active chart

FinUser

New Member
Joined
Aug 10, 2023
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
Hi all, I have a macro in excel that sets all the line weights in an active chart to a specific line width. The code is below. How do I adjust it: (1) to change width of a single series that I have selected on the chart (rather than all of them); and (2) change the colour (rather than the width) to one I specify (rgb(50,205,50)). Thank you!

Sub SetWeightsNormal()
Dim srs As series
For Each srs In ActiveChart.SeriesCollection
srs.Format.Line.Weight = 2#
Next
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try...

VBA Code:
        With Selection.Format.Line
            .Weight = 2#
            .ForeColor.RGB = RGB(50, 205, 50)
        End With

Although, you'll probably want to make sure that a series is selected before changing the formatting...

VBA Code:
    If TypeName(Selection) = "Series" Then
        With Selection.Format.Line
            .Weight = 2#
            .ForeColor.RGB = RGB(50, 205, 50)
        End With
    End If

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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