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!
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!