olorin_117
New Member
- Joined
- Jan 19, 2022
- Messages
- 18
- Office Version
- 2019
- Platform
- Windows
Hello. I have the code below that when the user inputs a value on a certain cell and logs it via a button, this is called to populate a simple line graph. At the beginning of each day the graph area is empty. I have tried to add a second data series but nothinh seems to work and can't figure out why.Try to add a seccon series collection but i get a bug every time. Any suggestions will be appreciated. I am working on excel 2016
VBA Code:
Sub ChartLinks(seconds As Variant)
Dim NewValues() As Variant
Dim NewXAxis() As Variant
Worksheets(1).ChartObjects(1).Activate
If ActiveChart.SeriesCollection.Count = 0 Then
ActiveChart.SeriesCollection.NewSeries
End If
For Each x In ActiveChart.SeriesCollection
NewValues = x.Values
ReDim Preserve NewValues(1 To UBound(NewValues) + 1) As Variant
seconds = CDbl(seconds)
NewValues(UBound(NewValues)) = seconds
x.Values = NewValues
ActiveSheet.Unprotect
NewXAxis = x.XValues
NewXAxis(UBound(NewXAxis)) = UBound(NewXAxis)
x.XValues = NewXAxis
ActiveSheet.Protect
Next x
End Sub