|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
- Sub abc()
- Dim X As ChartObject
- For Each X In Sheet164.ChartObjects
- X.Delete
- Next
- Dim 图表 As ChartObject, a, Arr, i
- a = ActiveSheet.Range("a1").End(xlDown).Row
- Set 图表 = ActiveSheet.ChartObjects.Add(530, 100, 700, 300)
- With 图表.Chart
- .SetSourceData Source:=ActiveSheet.Range("A2:b" & a), PlotBy:=xlColumns
- .ChartType = xlLine
- .HasLegend = False
- .Axes(xlValue, xlPrimary).MaximumScale = Excel.Application.WorksheetFunction.Max(ActiveSheet.Range("b:b")) * 1.03 '最大值
- .Axes(xlValue, xlPrimary).MinimumScale = Excel.Application.WorksheetFunction.Min(ActiveSheet.Range("b:b")) * 0.97 '最小值
- Arr = Sheet164.UsedRange
- For i = 2 To UBound(Arr)
- If Arr(i, 3) <> "" Then
- .FullSeriesCollection(1).Points(UBound(Arr) - i + 1).Select
- .SetElement (msoElementDataLabelCallout)
- End If
- Next
- With .FullSeriesCollection(1).DataLabels
- With .Format.TextFrame2.TextRange
- .Font.Fill.ForeColor.RGB = RGB(255, 0, 0)
- .Font.Size = 16
- End With
- End With
- End With
- 图表.Name = ActiveSheet.Name
- Set 图表 = Nothing
- End Sub
复制代码 |
|