Results 1 to 2 of 2

Thread: setting x values in line graph

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Posts
    17

    setting x values in line graph

    I have written a code that prompts the user to select x values then y values through inputboxes. However, I am unable to assign xaxis (the range of x values) to actually be used as ThemeColor x values in the graph and the only way I was able to use the y values was through setsources data.

    How can I assign the x values that the user selected to be used in the graph?

    Dim objChart As ChartObject
    Dim myChtRange As Range
    Dim xaxis As Range
    Dim yaxis As Range



    With ActiveSheet

    Set xaxis = Application.InputBox( _
    prompt:="Select a range containing the x axis data. For Cycle Time,highlight column D", _
    Title:="Select x axis", Default:=sInitialRange, Type:=8)
    On Error GoTo 0
    If xaxis Is Nothing Then Exit Sub ''must enter something or will exit program

    ' ask user for range that contains data for y axis
    On Error Resume Next
    Set yaxis = Application.InputBox( _
    prompt:="Select a range containing the y axis data. Condensor temp is column I", _
    Title:="Select y axis", Default:=sInitialRange, Type:=8)
    On Error GoTo 0
    If yaxis Is Nothing Then Exit Sub ''must enter something or will exit program

    On Error Resume Next

    Set myChtRange = Application.InputBox( _
    prompt:="Select a range where the chart should appear.", _
    Title:="Select Chart Position", Type:=8)
    On Error GoTo 0
    If myChtRange Is Nothing Then Exit Sub

    Set objChart = .ChartObjects.Add( _
    Left:=myChtRange.Left, top:=myChtRange.top, _
    Width:=myChtRange.Width, Height:=myChtRange.Height)

    With objChart.Chart
    .ChartArea.AutoScaleFont = False
    .ChartType = xlLine
    .SetSourceData Source:=yaxis
    .Axes(xlValue).CrossesAt = -100
    .HasTitle = True
    .ChartTitle.Characters.Text = "Freeze"
    .ChartTitle.Font.Bold = True
    .ChartTitle.Font.Size = 12
    End With



    End With


    Thank you!

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: setting x values in line graph

    Excel forum?

Posting Permissions

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



Click Here to Expand Forum to Full Width