ChartLegendCenter

Put chart legend at center of chart horizontally. Changes left and width only. Does not change anything else.
It activates chart to move its legend, then selects A1 to clear selection from chart.

CodeFunctionName
What is this?

Public

Tested

Original Work
Sub ChartLegendCenter(ChartName, Optional WB = "This", Optional Shee = "Active")
    ' Moves/resizes Legend of Chart to be in center of chart, without moving its top location
    '
    If WB = "This" Then WB = Thisworkbook.name
    If Shee = "Active" Then Shee = Workbooks(WB).ActiveSheet.Name
    Workbooks(WB).Activate
    Workbooks(WB).Worksheets(Shee).Activate
    ActiveSheet.ChartObjects(ChartName).Select
   
    ActiveChart.Legend.Left = 40
    ActiveChart.Legend.Width = ActiveChart.Width - 80
    Doevents
    ActiveSheet.Range("A1").Select
    ' ActiveSheet.ChartObjects("Chart 148").Activate
    ' ActiveChart.Legend.Select
    ' Selection.Left = 40
    ' Selection.Width = 1000.86
End Sub

ChartName, Optional WB = "This", Optional Shee = "Active"

Views 225

Downloads 127

CodeID
DB ID

ANmarAmdeen
635
Attachments
Revisions

v1.0

Thursday
December
21
2023