Hello-
My initial program generates a few iterations of similar charts depending on how many sets of 32000 datapoints there are. The X-axis is Date & Time, and Y-axis are different variables. I want to add a subroutine which plots an additional series from another page onto each of these plots, but this series is much smaller (maybe 10-20 x-y points), so I assign a range to each x and y series and plot the entire series to every plot, which drastically changes the x-axis range (as some of the points are outside the normal range of the previous 32000 set blocks).
I want to find a way to preserve the initial x-axis range before adding this new series, or filter this new series within the loop to only plot data that was from each block of the initial dataset range (1-32000), (32001 - 64001), etc.
Here is a portion of my code for the new series subroutine:
Sub AddEvents()
Dim FirstRow As Long
Dim LastRow As Long
Dim yColumn As Long
Dim yTitle As Range
Dim yData As Range
Dim xColumn As Long
Dim xTitle As Range
Dim xData As Range
Dim Eventser As Series
Dim i As Long
Dim j As Integer
Dim k As Long
Dim PWDplot As Chart
Worksheets("Events").Activate
For i = 1 To Rows.Count
If IsNumeric(Cells(i, "B").Value) And Cells(i, "B").Value <> "" Then
FirstRow = i
Exit For
End If
Next i
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
'Find x-axis data
With Rows(1)
Set xTitle = .Find("X - To Plot", LookIn:=xlValues, SearchDirection:=xlNext, LookAt:=xlWhole)
xColumn = xTitle.Column
End With
'Set x-axis data
Set xData = Range(Cells(FirstRow, xColumn), Cells(LastRow, xColumn))
'Find y-axis data
With Rows(1)
Set yTitle = .Find("Y - To Plot", LookIn:=xlValues, SearchDirection:=xlNext, LookAt:=xlWhole)
yColumn = yTitle.Column
End With
'Set y-axis data
Set yData = Range(Cells(FirstRow, yColumn), Cells(LastRow, yColumn))
k = ActiveWorkbook.Charts.Count
For j = 1 To k
Set PWDplot = ActiveWorkbook.Charts(j)
PWDplot.Activate
'add Event series
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(8).Name = "Events"
ActiveChart.SeriesCollection(8).XValues = xData
ActiveChart.SeriesCollection(8).Values = yData
'format Event series
Set Eventser = ActiveChart.SeriesCollection(8)
ActiveChart.SeriesCollection(8).Select
'line
With Selection.Format.Line
.Visible = msoFalse
End With
'Marker Fill
With Selection
.MarkerBackgroundColor = rgbYellow 'Marker Fill Color
.MarkerForegroundColor = msoThemeColorText1 'Marker Line Color
.MarkerStyle = xlTriangle
.Smooth = False
.MarkerSize = 8
.Shadow = False
End With
Next j
End Sub
Please someone help! I've looked around and cannot find a solution, and I have a feeling there is a pretty straight forward answer to this.
My initial program generates a few iterations of similar charts depending on how many sets of 32000 datapoints there are. The X-axis is Date & Time, and Y-axis are different variables. I want to add a subroutine which plots an additional series from another page onto each of these plots, but this series is much smaller (maybe 10-20 x-y points), so I assign a range to each x and y series and plot the entire series to every plot, which drastically changes the x-axis range (as some of the points are outside the normal range of the previous 32000 set blocks).
I want to find a way to preserve the initial x-axis range before adding this new series, or filter this new series within the loop to only plot data that was from each block of the initial dataset range (1-32000), (32001 - 64001), etc.
Here is a portion of my code for the new series subroutine:
Sub AddEvents()
Dim FirstRow As Long
Dim LastRow As Long
Dim yColumn As Long
Dim yTitle As Range
Dim yData As Range
Dim xColumn As Long
Dim xTitle As Range
Dim xData As Range
Dim Eventser As Series
Dim i As Long
Dim j As Integer
Dim k As Long
Dim PWDplot As Chart
Worksheets("Events").Activate
For i = 1 To Rows.Count
If IsNumeric(Cells(i, "B").Value) And Cells(i, "B").Value <> "" Then
FirstRow = i
Exit For
End If
Next i
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
'Find x-axis data
With Rows(1)
Set xTitle = .Find("X - To Plot", LookIn:=xlValues, SearchDirection:=xlNext, LookAt:=xlWhole)
xColumn = xTitle.Column
End With
'Set x-axis data
Set xData = Range(Cells(FirstRow, xColumn), Cells(LastRow, xColumn))
'Find y-axis data
With Rows(1)
Set yTitle = .Find("Y - To Plot", LookIn:=xlValues, SearchDirection:=xlNext, LookAt:=xlWhole)
yColumn = yTitle.Column
End With
'Set y-axis data
Set yData = Range(Cells(FirstRow, yColumn), Cells(LastRow, yColumn))
k = ActiveWorkbook.Charts.Count
For j = 1 To k
Set PWDplot = ActiveWorkbook.Charts(j)
PWDplot.Activate
'add Event series
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(8).Name = "Events"
ActiveChart.SeriesCollection(8).XValues = xData
ActiveChart.SeriesCollection(8).Values = yData
'format Event series
Set Eventser = ActiveChart.SeriesCollection(8)
ActiveChart.SeriesCollection(8).Select
'line
With Selection.Format.Line
.Visible = msoFalse
End With
'Marker Fill
With Selection
.MarkerBackgroundColor = rgbYellow 'Marker Fill Color
.MarkerForegroundColor = msoThemeColorText1 'Marker Line Color
.MarkerStyle = xlTriangle
.Smooth = False
.MarkerSize = 8
.Shadow = False
End With
Next j
End Sub
Please someone help! I've looked around and cannot find a solution, and I have a feeling there is a pretty straight forward answer to this.