Plotting Data on a Scatter Chart

bennhrios9

New Member
Joined
Sep 28, 2021
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
Hello, I have this data table that I need to plot on a scatter chart. How can I plot them quickly, maybe using VBA? In the screenshot below, each series would be two columns starting at C:D with "Temp" being the x-values and "Atten1" would being the y-values. There's about 1,800 series from this worksheet needed to be plotted so that's why I would like a way to do this quickly, please. The chart would look similar to what is on the screenshot.

Chart Screenshot.PNG
 

Attachments

  • Chart Screenshot.PNG
    Chart Screenshot.PNG
    78.2 KB · Views: 9

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I'm fairly certain that U won't be able to add 1800 series' to a chart but here's some code that seems like it would work for you. Adjust the sheet name to suit. HTH. Dave
Code:
Sub charttest()
Dim XRng As Range, YRng As Range, Cnt As Integer, LastRow As Integer
Dim objCht As ChartObject, LastCol As Integer, Cntr As Integer
Dim MyChart As Chart, ChartName As String, MyChartFrame As ChartObject
Dim ws As Worksheet

Set ws = Sheets("sheet1")
'remove previous chart
If ws.ChartObjects.Count > 0 Then
Set MyChartFrame = ws.ChartObjects(ws.ChartObjects.Count)
Set MyChart = MyChartFrame.Chart
'Remove SheetName from ChartName
ChartName = MyChart.Name
ChartName = Right(ChartName, Len(ChartName) - Len(ws.Name) - 1)
ws.ChartObjects(ChartName).Delete
End If

'add chart
Set objCht = ws.ChartObjects.Add(10, 20, 500, 200)
With ws
    LastCol = .Cells(3, .Columns.Count).End(xlToLeft).Column
    LastRow = .Range("C" & .Rows.Count).End(xlUp).Row
End With
For Cnt = 3 To LastCol Step 2
With ws
Set XRng = .Range(.Cells(3, Cnt), .Cells(LastRow, Cnt))
Set YRng = .Range(.Cells(3, Cnt + 1), .Cells(LastRow, Cnt + 1))
End With
Cntr = Cntr + 1
With objCht
.Chart.SeriesCollection.NewSeries
.Chart.SeriesCollection(Cntr).Values = XRng
.Chart.SeriesCollection(Cntr).XValues = YRng
.Chart.SeriesCollection(Cntr).ChartType = xlXYScatterSmoothNoMarkers
End With
Next Cnt
 
Upvote 0
Solution
I'm fairly certain that U won't be able to add 1800 series' to a chart but here's some code that seems like it would work for you. Adjust the sheet name to suit. HTH. Dave
Code:
Sub charttest()
Dim XRng As Range, YRng As Range, Cnt As Integer, LastRow As Integer
Dim objCht As ChartObject, LastCol As Integer, Cntr As Integer
Dim MyChart As Chart, ChartName As String, MyChartFrame As ChartObject
Dim ws As Worksheet

Set ws = Sheets("sheet1")
'remove previous chart
If ws.ChartObjects.Count > 0 Then
Set MyChartFrame = ws.ChartObjects(ws.ChartObjects.Count)
Set MyChart = MyChartFrame.Chart
'Remove SheetName from ChartName
ChartName = MyChart.Name
ChartName = Right(ChartName, Len(ChartName) - Len(ws.Name) - 1)
ws.ChartObjects(ChartName).Delete
End If

'add chart
Set objCht = ws.ChartObjects.Add(10, 20, 500, 200)
With ws
    LastCol = .Cells(3, .Columns.Count).End(xlToLeft).Column
    LastRow = .Range("C" & .Rows.Count).End(xlUp).Row
End With
For Cnt = 3 To LastCol Step 2
With ws
Set XRng = .Range(.Cells(3, Cnt), .Cells(LastRow, Cnt))
Set YRng = .Range(.Cells(3, Cnt + 1), .Cells(LastRow, Cnt + 1))
End With
Cntr = Cntr + 1
With objCht
.Chart.SeriesCollection.NewSeries
.Chart.SeriesCollection(Cntr).Values = XRng
.Chart.SeriesCollection(Cntr).XValues = YRng
.Chart.SeriesCollection(Cntr).ChartType = xlXYScatterSmoothNoMarkers
End With
Next Cnt
Thank you for your code. You were right, a chart can't have 1800 series. It says a chart can only have up to 256 series, so it won't run the code. Can you update the code so it can have up to 256 series?
 
Upvote 0
I'm fairly certain that U won't be able to add 1800 series' to a chart but here's some code that seems like it would work for you. Adjust the sheet name to suit. HTH. Dave
Code:
Sub charttest()
Dim XRng As Range, YRng As Range, Cnt As Integer, LastRow As Integer
Dim objCht As ChartObject, LastCol As Integer, Cntr As Integer
Dim MyChart As Chart, ChartName As String, MyChartFrame As ChartObject
Dim ws As Worksheet

Set ws = Sheets("sheet1")
'remove previous chart
If ws.ChartObjects.Count > 0 Then
Set MyChartFrame = ws.ChartObjects(ws.ChartObjects.Count)
Set MyChart = MyChartFrame.Chart
'Remove SheetName from ChartName
ChartName = MyChart.Name
ChartName = Right(ChartName, Len(ChartName) - Len(ws.Name) - 1)
ws.ChartObjects(ChartName).Delete
End If

'add chart
Set objCht = ws.ChartObjects.Add(10, 20, 500, 200)
With ws
    LastCol = .Cells(3, .Columns.Count).End(xlToLeft).Column
    LastRow = .Range("C" & .Rows.Count).End(xlUp).Row
End With
For Cnt = 3 To LastCol Step 2
With ws
Set XRng = .Range(.Cells(3, Cnt), .Cells(LastRow, Cnt))
Set YRng = .Range(.Cells(3, Cnt + 1), .Cells(LastRow, Cnt + 1))
End With
Cntr = Cntr + 1
With objCht
.Chart.SeriesCollection.NewSeries
.Chart.SeriesCollection(Cntr).Values = XRng
.Chart.SeriesCollection(Cntr).XValues = YRng
.Chart.SeriesCollection(Cntr).ChartType = xlXYScatterSmoothNoMarkers
End With
Next Cnt
Nvm. It works. It still plots the chart even with that error message. Thank you.
 
Upvote 0
It seems: 256 x 2 = 512 + 2 (start on column "C") = 514...
Code:
For Cnt = 3 To 514 Step 2
Dave
 
Upvote 0

Forum statistics

Threads
1,214,879
Messages
6,122,065
Members
449,064
Latest member
scottdog129

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