I need to populate an array with values from a range, then I want to use this array as the source data for a chart. I've tried setting the array as variant and as long and neither seem to work. Every time I try to run the code I get a type mismatch error at the line with .SetSourceData:=PlotRangeBar. Here's what I have so far:
Dim XRangeBar As Range
Dim PlotRangeBar() As Variant
Dim PlotRange As Range
Set XRangeBar = ActiveWorkbook.Sheets(2).Range("B" & DataStart & ":B" & DataEnd)
i = 0
For Row = DataStart To DataEnd
If Cells(Row, UsedColTimesheet).FormulaR1C1 <> "0" And Cells(Row, UsedColTimesheet) <> vbNullString Then
ReDim Preserve PlotRangeBar(i)
PlotRangeBar(i) = Cells(Row, UsedColTimesheet).Value
i = i + 1
End If
Next
ActiveWorkbook.Sheets(Sheets.Count).Select
ActiveSheet.Shapes.AddChart.Select
With ActiveChart
.ChartType = xlColumnStacked
.SetSourceData Source:=PlotRangeBar 'Error occurs here
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = XRangeBar
.SetElement (msoElementChartTitleCenteredOverlay)
.ApplyLayout (1)
.ChartTitle.Text = ResourceName & " - Hours per project"
.Legend.Delete
.ChartStyle = 18
.ProtectSelection = True
End With
I don't understand where the type mismatch comes from. I would very much apreciate any insight, thanks.