|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
试一下,是不是这样
Private Sub CommandButton1_Click()
Dim MyChart_Name As String
Dim Mysher As Integer
Dim MychSE As Series
Dim Mych As ChartObject '声明变量为嵌入式图表对象
MyChart_Name = "我的图表"
On Error Resume Next '如出错,则从出错行下一行开始执行
Set Mych = ActiveSheet.ChartObjects(MyChart_Name) '设置对象
'MsgBox Err.Number
If Err.Number <> 0 Then '设置对象出错,没有对象
Set Mych = ActiveSheet.ChartObjects.Add(200, 80, 680, 360) '添加嵌入图表,设置对象
Mych.Name = MyChart_Name '设置对象名称
End If
Err.Clear '清除Err对象
'On Error GoTo Myerr '如出错,则执行Myerr语句
With Mych.Chart
.ChartType = xlXYScatter '图表类型为散点图
For Each MychSE In .SeriesCollection
MychSE.Delete '删除图表中的所有系列
Next
End With
Mysher = Range("A65536").End(xlUp).Row
csh = 2
For i = 2 To Mysher
If i > 65536 Then Exit For
If Cells(i, 1) <> Cells(i + 1, 1) Then
Set MychSE = Mych.Chart.SeriesCollection.NewSeries '添加系列
MychSE.XValues = Range(Cells(csh, 3), Cells(i, 3)) '设置x值
MychSE.Values = Range(Cells(csh, 2), Cells(i, 2)) '设置y值
MychSE.Name = Cells(i, 1) '设置名称
csh = i + 1
End If
Next i
With ActiveChart.Axes(xlCategory) '设置X轴
.MinimumScale = 0 'X轴的最小刻度值
.MaximumScale = 180 'X轴的最大刻度值
.MinorUnit = 4 'X轴次要刻度单位
.MajorUnit = 20 'X轴主要刻度单位
.Crosses = 0 'X轴与Y轴相交的点
End With
With Mych.Chart.Axes(xlValue) '设置Y轴
.MinimumScale = 0.01 'Y轴的最小刻度值
.MaximumScale = 1000 'Y轴的最大刻度值
.MinorUnit = 10 'Y轴次要刻度单位
.MajorUnit = 10 'Y轴主要刻度单位
'.Crosses = xlCustom 'Y轴与X轴相交的点
.CrossesAt = 0.01 'Y轴与X轴相交的点
.ScaleType = xlLogarithmic '设置Y轴的刻度类型
End With
Mych.Activate '对象激活
Myerr:
Exit Sub
End Sub
测试.zip
(53.86 KB, 下载次数: 174)
|
评分
-
1
查看全部评分
-
|