vba控制图表,excel图表,一键完成

https://docs.microsoft.com/zh-cn/office/vba/api/excel.worksheet.chartobjects

运行宏就显示图表

vba控制图表,excel图表,一键完成

Sub test() Dim ch As ChartObject, ws As Worksheet Dim lastrow& Application.ScreenUpdating = False Set ws = Worksheets("Sheet1") If ws.ChartObjects.Count > 0 Then ws.ChartObjects.Delete lastrow = ws.Range("a" & Rows.Count).End(xlUp).Row Set ch = ws.ChartObjects.Add(ws.[f5].Left, ws.[f5].Top, 360, 215) \' ch.Name = ws.[b1] With ch.Chart .ChartType = xlLineMarkers .SeriesCollection.NewSeries .SeriesCollection(1).Values = ws.Range("b3:b" & lastrow) .SeriesCollection(1).XValues = ws.Range("a3:a" & lastrow) .SeriesCollection(1).Name = ws.[b2] .SeriesCollection.NewSeries .SeriesCollection(2).Values = ws.Range("c3:c" & lastrow) .SeriesCollection(2).XValues = ws.Range("a3:a" & lastrow) .SeriesCollection(2).Name = ws.[c2] End With With ch.Chart.Axes(xlValue, xlPrimary) .CrossesAt = .MinimumScale .TickLabels.Font.Size = 8 .MajorGridlines.Border.ColorIndex = 5 End With With ch.Chart.Axes(xlCategory) .TickLabels.Font.Size = 8 End With With ch.Chart .HasTitle = True .ChartTitle.Text = ch.Name .ChartTitle.Font.Size = 18 .ChartTitle.Left = 137 .ChartTitle.Top = 2 .HasLegend = False .PlotArea.Width = 347 .PlotArea.Left = 0 .PlotArea.Top = 20 .PlotArea.Height = 181 .Export ThisWorkbook.Path & "\test.gif" End With ch.Delete Set ch = Nothing End Sub

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgysps.html