G
Guest
I want to tidy up and reduce the amount of code if possible by handling
repetative actions such as adding Series to a chart.
Currently I am using something like this below to add a second Series to the
ActiveChart but also use almost identical code for Series 3, 4, 5 etc up to a
dozen or so. I sthere any way I can reference different Variables within
this code e.g. for Pri_Chart_Source_Sheet_2, Pri_Chart_Source_Sheet_3 ,
Pri_Chart_Source_Sheet_4 etc
With ActiveChart
If Pri_Series_Data_Column_2 <> Empty Then
Set PlotValuesSeries =
Sheets(Pri_Chart_Source_Sheet_2).Range(Pri_Series_Data_Column_2 & "2:" &
Pri_Series_Data_Column_2 & Last_Row_of_Pri_Source_Sheet_2)
Set PlotXValuesSeries =
Sheets(Pri_Chart_Source_Sheet_2).Range(Pri_Timestamp_Data_Column_2 & "2:" &
Pri_Timestamp_Data_Column_2 & Last_Row_of_Pri_Source_Sheet_2)
Series_Index_No = Series_Index_No + 1
.SeriesCollection.Add
Sheets(Pri_Chart_Source_Sheet_2).Range(Pri_Series_Data_Column_2 & ":" &
Pri_Series_Data_Column_2)
.SeriesCollection(Series_Index_No).Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlAutomatic
.ColorIndex = 5
End With
With Selection
.MarkerStyle = xlNone
End With
With Worksheets(Pri_Chart_Source_Sheet_2)
ActiveChart.SeriesCollection(Series_Index_No).XValues =
PlotXValuesSeries
ActiveChart.SeriesCollection(Series_Index_No).Values =
PlotValuesSeries
End With
End If
End With
repetative actions such as adding Series to a chart.
Currently I am using something like this below to add a second Series to the
ActiveChart but also use almost identical code for Series 3, 4, 5 etc up to a
dozen or so. I sthere any way I can reference different Variables within
this code e.g. for Pri_Chart_Source_Sheet_2, Pri_Chart_Source_Sheet_3 ,
Pri_Chart_Source_Sheet_4 etc
With ActiveChart
If Pri_Series_Data_Column_2 <> Empty Then
Set PlotValuesSeries =
Sheets(Pri_Chart_Source_Sheet_2).Range(Pri_Series_Data_Column_2 & "2:" &
Pri_Series_Data_Column_2 & Last_Row_of_Pri_Source_Sheet_2)
Set PlotXValuesSeries =
Sheets(Pri_Chart_Source_Sheet_2).Range(Pri_Timestamp_Data_Column_2 & "2:" &
Pri_Timestamp_Data_Column_2 & Last_Row_of_Pri_Source_Sheet_2)
Series_Index_No = Series_Index_No + 1
.SeriesCollection.Add
Sheets(Pri_Chart_Source_Sheet_2).Range(Pri_Series_Data_Column_2 & ":" &
Pri_Series_Data_Column_2)
.SeriesCollection(Series_Index_No).Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlAutomatic
.ColorIndex = 5
End With
With Selection
.MarkerStyle = xlNone
End With
With Worksheets(Pri_Chart_Source_Sheet_2)
ActiveChart.SeriesCollection(Series_Index_No).XValues =
PlotXValuesSeries
ActiveChart.SeriesCollection(Series_Index_No).Values =
PlotValuesSeries
End With
End If
End With