Я немного изменил ваш код, и он прекрасно работает, и я добавил несколько полезных замечаний, чтобы помочь вам с программированием:
Sub Chart1()
Dim LupCol As Long, LupRow As Long, LastRow As Long
' note: use Long not Integer, long story, but it's better with no drawbacks
' also, need to dim each variable as a type, or they'll be variants
Dim rCount As Long
LupCol = 2
LupRow = 2
rCount = 92
LastRow = rCount - 1
Dim TimeArr As Variant, TempArr As Variant
With Worksheets("Process_Data")
' don't need to activate the sheet, just reference it
' also, use .Value to populate the arrays
TimeArr = .Range(.Cells(LupRow, LupCol), .Cells(LastRow, LupCol)).Value
TempArr = .Range(.Cells(LupRow, LupCol + 1), .Cells(LastRow, LupCol + 1)).Value
End With
Dim ChartSheet1 As Chart
Set ChartSheet1 = Charts.Add
ActiveChart.ChartArea.Clear
With ChartSheet1
.ChartType = xlXYScatterLinesNoMarkers
With .SeriesCollection.NewSeries
' need to add series before you populate it
.XValues = TimeArr
.Values = TempArr
End With
.HasTitle = True
.ChartTitle.Text = "Air Side Temperatures"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Temperature in degC"
.Axes(xlValue, xlPrimary).MinimumScale = 0
End With
End Sub
Любая причина, по которой вы хотите использовать кодированные массивы, а не диапазоны рабочих листов в качестве данных диаграммы?
Чтобы использовать диапазоны:
Sub Chart2()
Dim LupCol As Long, LupRow As Long, LastRow As Long
Dim rCount As Long
LupCol = 2
LupRow = 2
rCount = 92
LastRow = rCount - 1
Dim TimeArr As Range, TempArr As Range
With Worksheets("Process_Data")
Set TimeArr = .Range(.Cells(LupRow, LupCol), .Cells(LastRow, LupCol))
Set TempArr = .Range(.Cells(LupRow, LupCol + 1), .Cells(LastRow, LupCol + 1))
End With
Dim ChartSheet1 As Chart
Set ChartSheet1 = Charts.Add
ActiveChart.ChartArea.Clear
With ChartSheet1
.ChartType = xlXYScatterLinesNoMarkers
With .SeriesCollection.NewSeries
.XValues = TimeArr 'RUN TIME ERROR of invalid parameter
.Values = TempArr
End With
.HasTitle = True
.ChartTitle.Text = "Air Side Temperatures"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Temperature in degC"
.Axes(xlValue, xlPrimary).MinimumScale = 0
End With
End Sub