• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to specify which chart a macro should change

lingyai

New Member
Hi, some years ago I got some help creating the code below, which sets chart parameters (scale etc) from values in named worksheet cells. It works great. Except that it does this to every chart on a given worksheet, while now, I only want it to do something to one specific chart, which I've named "Target_chart". Sorry, I know this is something quite basic; but how can I modify this code to do this?

Code:
Sub ChangeAxisScales()
   Dim objCht As ChartObject
   For Each objCht In ActiveSheet.ChartObjects
      With objCht.Chart
         ' Value (Y) Axis
         With .Axes(xlValue)
            .MaximumScale = ActiveSheet.Range("Axis_max").Value
            .MinimumScale = ActiveSheet.Range("Axis_min").Value
            .MajorUnit = ActiveSheet.Range("Unit").Value
         End With
 
Code:
Sub ChartSettings()
  Dim c As Chart
  Set c = Sheet1.ChartObjects("Target_chart").Chart
  ' Value (Y) Axis
  With c.Axes(xlValue)
    .MaximumScale = ActiveSheet.Range("Axis_max").Value
    .MinimumScale = ActiveSheet.Range("Axis_min").Value
    .MajorUnit = ActiveSheet.Range("Unit").Value
  End With
End Sub
 
Back
Top