作者:绿色风
分类:
时间:2022-08-17
浏览:146
楼主 omnw |
Q:如何用VBA绘制纵向折线图? A:根据数据区域的数值,自动在图形区域绘制出折线图。具体代码如下:
- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim nRow%, i%, j%
- Dim BeginR As Range, EndR As Range
- If Target.Column > 1 Or Target.Columns.Count > 1 Then Exit Sub
- Application.ScreenUpdating = False
- Application.EnableEvents = False
- nRow = Range("A65536").End(xlUp).Row
- If Me.Shapes.Count > 0 Then '删除已有的图形
- Me.Shapes.SelectAll
- Selection.Delete
- End If
- Range("B3:K" & nRow).FillDown
- Set BeginR = Range("B3")
- For i = 3 To nRow '
- Set EndR = Range("B" & i).Offset(0, Cells(i, 1))
- Set DrawLine = Me.Shapes.AddLine(BeginR.Left + BeginR.Width / 2, _
- BeginR.Top + BeginR.Height / 2, EndR.Left + EndR.Width / 2, _
- EndR.Top + EndR.Height / 2).Line '绘制线条
- Set BeginR = EndR
- Next i
- ActiveSheet.DrawingObjects.ShapeRange.Group '组合所有的图形
- With ActiveSheet.DrawingObjects.ShapeRange.Line
- .DashStyle = msoLineSolid '设置线条的格式
- .Weight = 1.5 '设置线条的粗细
- .ForeColor.SchemeColor = 10 '设置线条的颜色
- End With
- Application.EnableEvents = True
- Application.ScreenUpdating = True
- Set BeginR = Nothing
- Set EndR = Nothing
- End Sub
折线图附件.rar |
2楼 ayx365 |
厉害
|
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一