Macro for formatting lines on a line 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. However, as well as changing any line on a line graph (what I want), on mixed graphs it also adds a border to column or area charts, which is something I don't want! Any ideas on how I adjust the code to only change lines on series that are line charts but not any other chart type? Thank you!

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

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You can check for a line chart using the ChartType property of the Chart object...

VBA Code:
Sub SetWeightsNormal()

    Dim srs As Series
    
    If ActiveChart.ChartType = xlLine Then
        For Each srs In ActiveChart.SeriesCollection
            srs.Format.Line.Weight = 2#
        Next
    End If
    
End Sub

Hope this helps!
 
Upvote 1
Solution

Forum statistics

Threads
1,224,004
Messages
6,175,904
Members
452,682
Latest member
ghorne

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