VBA 散点图ChartSheet
Sub al() Call CreatingChartOnChartSheet("Optimize ELVSS 1000nits", "R", 167, 9) Call CreatingChartOnChartSheet("Optimize ELVSS 1000nits", "G", 167, 11) Call CreatingChartOnChartSheet("Optimize ELVSS 1000nits", "B", 167, 13) End Sub Sub CreatingChartOnChartSheet(Na As String, col As String, c%, r%) Dim xrng As Range Dim yrng1 As Range Dim yrng2 As Range Dim yrng3 As Range Dim yrng4 As Range Dim yrng5 As Range With Sheets(Na) Set xrng = .Range("c25:c95") Set yrng1 = .Range(.Cells(c, r), .Cells(c + 70, r)) Set yrng2 = .Range(.Cells(c, r + 10), .Cells(c + 70, r + 10)) Set yrng3 = .Range(.Cells(c, r + 20), .Cells(c + 70, r + 20)) Set yrng4 = .Range(.Cells(c, r + 30), .Cells(c + 70, r + 30)) Set yrng5 = .Range(.Cells(c, r + 40), .Cells(c + 70, r + 40)) End With Application.DisplayAlerts = False On Error Resume Next Charts("Red").Delete On Error GoTo 0 Application.DisplayAlerts = True With Charts.Add 'remove any auto-plotted data Do While .SeriesCollection.Count > 0 .SeriesCollection(1).Delete Loop With .SeriesCollection.NewSeries .Name = "=""-20du""" .XValues = xrng .Values = yrng1 End With With .SeriesCollection.NewSeries .Name = "=""-10du""" .XValues = xrng .Values = yrng2 End With With .SeriesCollection.NewSeries .Name = "=""0du""" .XValues = xrng .Values = yrng3 End With With .SeriesCollection.NewSeries .Name = "=""25du""" .XValues = xrng .Values = yrng4 End With With .SeriesCollection.NewSeries .Name = "=""50du""" .XValues = xrng .Values = yrng5 End With .SetElement msoElementChartTitleAboveChart .Name = Na & col .ChartTitle.Text = Na & col .SetElement (msoElementLegendBottom) '.Axes(xlCategory, xlPrimary).HasTitle = True '.Axes(xlCategory, xlPrimary).AxisTitle.Text = "ELVSS(V)" '.Axes(xlValue, xlPrimary).HasTitle = True '.Axes(xlValue, xlPrimary).AxisTitle.Text = "Power (kW)" .ChartType = xlXYScatterSmooth '.Axes(xlCategory).MajorUnit = 1 '.Axes(xlCategory).MinorUnit = 1 End With End Sub