Userform Chart, adding, deleting series with combobox entries

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?

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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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