CALLING PARTICULAR CHARTS

J

Jase

I have this code that allows me to change the scaling of ALL charts from
specified cells I have set up. Is there a way that instead of changing all
charts that I can pick a couple particular charts instead. For instance if I
have 10 charts and I just want to rescale charts:2,5,6 and 9

Private Sub Worksheet_Change(ByVal Target As Range)

For iChart = 1 To ActiveSheet.ChartObjects.Count
Set cht = ActiveSheet.ChartObjects(iChart).Chart


With cht.Axes(xlValue)
.MinimumScale = ActiveSheet.Range("B24")
.MaximumScale = ActiveSheet.Range("B23")
End With

With cht.Axes(xlCategory)
.MinimumScale = ActiveSheet.Range("C24")
.MaximumScale = ActiveSheet.Range("C23")
End With

Next
End Sub
 
A

Andy Pope

Hi,

Try this, which will reference the specified chart indexes and only run
when the cells B23:C24 are changed.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim iChart
Dim cht

If Not Intersect(Target, Range("B23:C24")) Is Nothing Then
For Each iChart In Array(2, 5, 6, 9)
Set cht = ActiveSheet.ChartObjects(iChart).Chart
With cht.Axes(xlValue)
.MinimumScale = ActiveSheet.Range("B24")
.MaximumScale = ActiveSheet.Range("B23")
End With

With cht.Axes(xlCategory)
.MinimumScale = ActiveSheet.Range("C24")
.MaximumScale = ActiveSheet.Range("C23")
End With

Next
End If
End Sub

Cheers
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top