Trying to set x data and y data for a chart

Boogerbut74

New Member
Joined
Oct 17, 2022
Messages
26
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub graph_creator()


'Create a chart
  Set cht = ActiveSheet.ChartObjects.Add( _
    Left:=ActiveCell.Left, _
    Width:=450, _
    Top:=ActiveCell.Top, _
    Height:=250)

'Give chart x and y data
Set xRange = Range("=$D10:$D150 ")
    Set yRange = Range("=$F10:$V2360")
    ChartObjects.SeriesCollection(1).XValues = "=Raw!xRange"
    ChartObjects.SeriesCollection(1).Values = "=Raw!yRange"

'Determine the chart type
  
  cht.Chart.ChartType = xlXYScatterLines
  

End Sub

Right now my graph didn't do the x data so i tried this but it didn't work so if anyone has solutions please let me know thank you.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
This is a working example:
VBA Code:
Sub graph_creator()
Dim cht As Chart
'
'Create a chart
  Set cht = ActiveSheet.ChartObjects.Add( _
    Left:=ActiveCell.Left, _
    Width:=450, _
    Top:=ActiveCell.Top, _
    Height:=250).Chart
    
'Give chart x and y data
    cht.SeriesCollection.NewSeries           'Serie #1
    cht.SeriesCollection(1).XValues = Sheets("RAW").Range("D3:D10")
    cht.SeriesCollection(1).Values = Sheets("RAW").Range("E3:E10")
    cht.SeriesCollection.NewSeries          'Serie #2
    cht.SeriesCollection(2).Values = Sheets("RAW").Range("F3:F10")
'
'more series and more values here
'
'Set the chart type
  cht.ChartType = xlXYScatterLines
End Sub

Try to adapt to your situation...
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top