Is there any change when having the chart in different sheet?
Is there any change when having the chart in different sheet?
Yes. The routine would need to know which sheet to check.
So I have added the min and max values to the argument list.
And the sheet level code can pass the relevant information![]()
Sub AxisChange(Cht As Chart, MinValue, MaxValue) With Cht.Axes(xlValue) .MinimumScale = MinValue .MaximumScale = MaxValue End With End Sub
![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("A1:A2"), Target) Is Nothing Then AxisChange ActiveSheet.ChartObjects(1).Chart, Range("A1").Value, Range("A2").Value End If End Sub
Hi Andy. Thx for your wise suggestions. I managed to use all the code you sent including the part for running the code when changing the cells.
I'm not able to use it when the chart is in different datasheet though. I think the problem is in defining the variables MinValue & and Maxvalue as inputs you suggested in the rutine you sent. All the cells are in sheet1 and the chart is within the same book as chart sheet.
How should I do that? Is there any modification in here?![]()
Sub AxisChange(Cht As Chart, MinValue, MaxValue) With Cht.Axes(xlValue) .MinimumScale = MinValue .MaximumScale = MaxValue End With End Sub
Thx![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("A1:A2"), Target) Is Nothing Then AxisChange ActiveSheet.ChartObjects(1).Chart, Range("A1").Value, Range("A2").Value End If End Sub
The AxisChange routine would be in a standard code module and is cabable of handling the first chartobject on any sheet.
But the trick to getting it to work on multiple sheets is to add the Worksheet_Change code to each sheet that has a chart and cell information.
See revised example.
Ok, it's a bit more clear!! but still i get an error about the chart objects property when trying to use the values from the datasheet to the chart. what could it be? I attached and example to clarify my question.
Thx
Hi Andy. I've tried everything which is in my hands but i'm not able to find how to find the solution when having the data and the chart in diferent data sheet.
I've got in the main module the following code:
Attached to the "data" datasheet this one:![]()
Sub AxisChange(Cht As Chart, MinValue, MaxValue) With Cht.Axes(xlValue) .MinimumScale = MinValue .MaximumScale = MaxValue End With End Sub
And attached to the "chart" datasheet the same code as for the datasheet. I also tried without code in the "chart" datasheet and i made several changes concerning the name of variables (i.e. Sheets("Sheet1").Range("1")) and so on but still I get errors when running it....![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("A1:A2"), Target) Is Nothing Then AxisChange ActiveSheet.ChartObjects(1).Chart, Range("A1").Value, Range("A2").Value End If End Sub
Any hint.
Thank you very much.
I can not seem to donwload your example.
Can you email it to me direct? andy AT andypoe DOT info
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks