Consulting

Results 1 to 2 of 2

Thread: Excel VBA error method 'minimumscaleisauto' of object 'axes' failed

  1. #1
    VBAX Newbie
    Joined
    Aug 2010
    Posts
    1
    Location

    Excel VBA error method 'minimumscaleisauto' of object 'axes' failed

    Hi,

    I'm getting an error when I run my program that says "error method 'minimumscaleisauto' of object 'axes' failed". Everything works just how I want it to but this error box keeps coming up. I have searched for an answer and what everything has said was it is related to the add-ins, but when I tried changing it, the error kept coming up.

    Here's where I think the problem is, since when I go to debug, this is where it brings me:

    [VBA]Public Sub CreateChart()

    Dim ChartFileName As String
    Dim DataRange As String
    Dim co As ChartObject
    Dim cw As Long, rh As Long

    ' form for chart MUST be named 'ChartForm'

    If (ShowChartInForm) Then
    Load ChartForm
    End If

    ' create the range designation based on the user input

    DataRange = ConvertCellsToRange(StartRowID, StartColumnID, EndRowID, EndColumnID)
    Range(DataRange).Select
    'Sheets(ChartSheetName).Select
    'MsgBox ActiveSheet.ChartObjects.Count
    If ActiveSheet.ChartObjects.Count > 0 Then
    ActiveSheet.ChartObjects(1).Delete
    End If

    ' Get data for positioning chart
    cw = Columns(1).Width
    rh = Rows(1).Height

    ' Position chart using column width and row height units
    Set co = ActiveSheet.ChartObjects.Add(cw * LeftOfChart, rh * TopOfChart, cw * WidthOfChart, rh * HeightOfChart)

    'Charts.Add
    co.Chart.ChartType = xlLine
    co.Chart.SetSourceData Source:=Sheets(ChartSheetName).Range(DataRange), PlotBy:=xlColumns
    ActiveSheet.Select
    'Sheets(ChartSheetName).Select
    co.Chart.Location Where:=xlLocationAsObject, Name:=ChartSheetName
    With co.Chart
    If (ChartTitle <> "") Then
    .HasTitle = True
    .ChartTitle.Characters.Text = ChartTitle
    End If

    If (XAxisTitle <> "") Then
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = XAxisTitle
    End If

    If (YAxisTitle <> "") Then
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = YAxisTitle
    End If
    End With

    With co.Chart.Axes(xlCategory)
    .HasMajorGridlines = VerticalGridlinesShown

    .HasMinorGridlines = False

    End With

    With co.Chart.Axes(xlValue)
    .HasMajorGridlines = HorizontalGridlinesSHown
    .HasMinorGridlines = False
    End With
    co.Chart.SetSourceData Source:=Sheets(ChartSheetName).Range(DataRange), PlotBy:=xlColumns
    co.Chart.PlotArea.Select
    co.Chart.PlotArea.Interior.ColorIndex = xlNone
    If (Not AxisBoxShown) Then
    co.Chart.PlotArea.Border.Color = vbWhite
    End If
    co.Chart.HasLegend = True
    co.Chart.Axes(xlCategory).Select
    With co.Chart.Axes(xlCategory)
    If (XAxisMin > XAxisMax) Then
    .MinimumScaleIsAuto = True
    .MaximumScaleIsAuto = True
    Else
    .MinimumScale = XAxisMin
    .MaximumScale = XAxisMax
    End If
    .MinorUnitIsAuto = True
    .MajorUnitIsAuto = True
    If (XValueOfIntersection = 987654321) Then
    .Crosses = xlAutomatic
    Else
    .Crosses = xlCustom
    .CrossesAt = XValueOfIntersection
    End If
    .ReversePlotOrder = False
    .ScaleType = xlLinear
    .DisplayUnit = xlNone
    End With
    co.Chart.Axes(xlValue).Select
    With co.Chart.Axes(xlValue)
    If (YAxisMin > YAxisMax) Then
    .MinimumScaleIsAuto = True
    .MaximumScaleIsAuto = True
    Else
    .MinimumScale = YAxisMin
    .MaximumScale = YAxisMax
    End If
    .MinorUnitIsAuto = True
    .MajorUnitIsAuto = True
    If (YValueOfIntersection = 987654321) Then
    .Crosses = xlAutomatic
    Else
    .Crosses = xlCustom
    .CrossesAt = YValueOfIntersection
    End If
    .ReversePlotOrder = False
    .ScaleType = xlLinear
    .DisplayUnit = xlNone
    End With

    If (ShowChartInForm) Then
    ' the Picture control is used to show the Chart
    ChartForm.Image1.Width = ChartForm.Width
    ChartForm.Image1.Height = ChartForm.Height - 22
    co.Chart.Parent.Width = ChartForm.Image1.Width
    co.Chart.Parent.Height = ChartForm.Image1.Height

    ' Save chart as GIF
    ChartFileName = ThisWorkbook.Path & Application.PathSeparator & "VBAChart!^@%#$.gif"
    co.Chart.Export Filename:=ChartFileName, FilterName:="GIF"

    ' Show the chart
    ChartForm.Image1.Picture = LoadPicture(ChartFileName)
    ' delete the temporary chart image file
    Kill ChartFileName

    ' delete the chart from the spreadsheet
    If ActiveSheet.ChartObjects.Count > 0 Then
    ActiveSheet.ChartObjects(1).Delete
    End If
    End If

    ' form for chart MUST be named 'ChartForm'
    If (ShowChartInForm) Then
    ChartForm.Show
    End If
    End Sub
    [/VBA]

    I'm really confused, I've tried changing the add-ins, and changing the "minimumscalisauto" value to false and nothing changes.

    Thank you

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    There are a lot of unknowns in your code, but that may not matter; speaking generally and guessing a bit, when you're trying to minimumscaleisauto, is this not already the setting for a new chart? If so can't you just miss them out altogether?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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