Closed Thread
Results 1 to 17 of 17

Changing scale axis

Hybrid View

  1. #1
    Registered User
    Join Date
    05-22-2008
    Posts
    22
    Is there any change when having the chart in different sheet?

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481
    Yes. The routine would need to know which sheet to check.

    So I have added the min and max values to the argument list.

    Sub AxisChange(Cht As Chart, MinValue, MaxValue)
        With Cht.Axes(xlValue)
            .MinimumScale = MinValue
            .MaximumScale = MaxValue
        End With
    End Sub
    And the sheet level code can pass the relevant information

    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
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    05-22-2008
    Posts
    22
    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.

    Sub AxisChange(Cht As Chart, MinValue, MaxValue)
        With Cht.Axes(xlValue)
            .MinimumScale = MinValue
            .MaximumScale = MaxValue
        End With
    End Sub
    How should I do that? Is there any modification in here?

    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
    Thx

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481
    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.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-22-2008
    Posts
    22
    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
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-22-2008
    Posts
    22
    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:

    Sub AxisChange(Cht As Chart, MinValue, MaxValue)
        With Cht.Axes(xlValue)
            .MinimumScale = MinValue
            .MaximumScale = MaxValue
        End With
    End Sub
    Attached to the "data" datasheet this one:

    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
    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....
    Any hint.

    Thank you very much.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481
    I can not seem to donwload your example.
    Can you email it to me direct? andy AT andypoe DOT info

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1