I reckon
Private Sub ComboBox1_Click()
Dim SheetName As Worksheet
Dim cht As Chart
Dim lastdatapoint As Long
Select Case ComboBox1.Value
Case "FB1", "FB2", "FB3"
Set SheetName = Worksheets(ComboBox1.Value)
Case Else
Exit Sub
End Select
Application.ScreenUpdating = False
With SheetName
lastdatapoint = .Range("B" & .Rows.Count).End(xlUp).Row
End With
With Worksheets("Plots")
'delete any other chart on the sheet before proceding
On Error Resume Next
.ChartObjects.Delete
' bad idea to leave errors suppressed!
On Error GoTo 0
Set cht = .Shapes.AddChart.Chart
End With
With cht
.ChartType = xlLine
.SetSourceData SheetName.Range("$R$3:$R" & lastdatapoint)
.SeriesCollection(1).XValues = SheetName.Range("$B$3:$B" & lastdatapoint)
'x axis label spacing
.Axes(xlCategory).TickMarkSpacing = 10
.Axes(xlCategory).TickLabelSpacing = 10
'axes titles
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Temperature (C)"
'make the graph area bigger
With .Parent
.Height = 325
.Width = 500
End With
End With
Application.ScreenUpdating = True
Set SheetName = Nothing
End Sub
Bookmarks