Keeping static x-axis with new series

rsudhakar

New Member
Joined
Sep 16, 2014
Messages
1
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.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top