RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
So I have a userform with 4 comboboxes and in each are two choices - 1. an element (Mn, Zn, etc.) and 2. the word "omit"
So I want to be able to interactively plot these on a graph. With the code below I can plot the whole collection but I can't use the userform to remove series.
Thoughts?
So I want to be able to interactively plot these on a graph. With the code below I can plot the whole collection but I can't use the userform to remove series.
Thoughts?
Code:
Private Sub CommandButton1_Click()
Dim MyChart As Chart
Dim ChartData1 As Range
Dim ChartData2 As Range
Dim ChartData3 As Range
Dim ChartData4 As Range
Dim ChartIndex1 As Integer
Dim ChartIndex2 As Integer
Dim ChartIndex3 As Integer
Dim ChartIndex4 As Integer
Dim ChartIndex5 As Integer
Dim ChartIndex6 As Integer
Dim ChartName1 As String
Dim ChartName2 As String
Dim ChartName3 As String
Dim ChartName4 As String
Dim ChartName5 As String
Dim ChartName6 As String
Application.ScreenUpdating = False
ActiveWindow.Zoom = 120
ChartIndex1 = ComboBox1.ListIndex 'Mg
ChartIndex2 = ComboBox2.ListIndex 'Mn
ChartIndex3 = ComboBox3.ListIndex 'Si
ChartIndex4 = ComboBox4.ListIndex 'Zn
ChartIndex5 = ComboBox5.ListIndex 'TOC
ChartIndex6 = ComboBox6.ListIndex 'Various Tanks
ChartName1 = "Mg"
ChartName2 = "Mn"
ChartName3 = "Si"
ChartName4 = "Zn"
ChartName5 = "TOC"
ActiveSheet.Range("E1").Select
Set MyChart = ActiveSheet.Shapes.AddChart(xlXYScatterLines).Chart
'Flash Discharge
If ChartIndex6 = 0 Then
If ChartIndex1 = 0 Then Set ChartData1 = Worksheets("Minor Element Profiles").Range("AF7:AF37") 'Mg
With MyChart
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = ChartName1
.SeriesCollection(1).Values = ChartData1
.SeriesCollection(1).XValues = Worksheets("Minor Element Profiles").Range("B7:B37")
End With
If ChartIndex2 = 0 Then Set ChartData2 = Worksheets("Minor Element Profiles").Range("AG7:AG37") 'Mn
With MyChart
.SeriesCollection.NewSeries
.SeriesCollection(2).Name = ChartName2
.SeriesCollection(2).Values = ChartData2
.SeriesCollection(2).XValues = Worksheets("Minor Element Profiles").Range("B7:B37")
End With
If ChartIndex3 = 0 Then Set ChartData3 = Worksheets("Minor Element Profiles").Range("AH7:AH37") 'Si
With MyChart
.SeriesCollection.NewSeries
.SeriesCollection(3).Name = ChartName3
.SeriesCollection(3).Values = ChartData3
.SeriesCollection(3).XValues = Worksheets("Minor Element Profiles").Range("B7:B37")
End With
If ChartIndex4 = 0 Then Set ChartData4 = Worksheets("Minor Element Profiles").Range("AI7:AI37") 'Zn
With MyChart
.SeriesCollection.NewSeries
.SeriesCollection(4).Name = ChartName4
.SeriesCollection(4).Values = ChartData4
.SeriesCollection(4).XValues = Worksheets("Minor Element Profiles").Range("B7:B37")
End With
With MyChart
.Axes(xlCategory).Select
Selection.TickLabels.NumberFormat = "m/d/yyyy"
Selection.TickLabels.NumberFormat = "[$-409]mmm-dd;@"
.Axes(xlValue).Select
Selection.TickLabels.NumberFormat = "#,##0.00"
Selection.TickLabels.NumberFormat = "#,##0.0"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Text = "Concentration (mg/L)"
End With
End If
Dim ImageName As String
ImageName = Application.DefaultFilePath & Application.PathSeparator & "TempChart.jpeg"
MyChart.Export Filename:=ImageName
ActiveSheet.ChartObjects(1).Delete
Application.ScreenUpdating = True
A1_Elemental_Set.Image1.Picture = LoadPicture(ImageName)
End Sub