网站首页 > 技术文章 正文
最近,本人连续发布了三篇关于制作福彩双色球动态幻圆图的VBA+Excel的方法及其程序的系列文章,收到广大友友的喜爱,我也备受鼓舞,继续为友友提供相关的内容,反馈友友。
关注我,进入我的主页,你可以看到更多内容。
福彩双色球篮球折线图制作的VBA+Excel的方法及其程序的内容如下。
一、新建一个Excel工作簿。
1、按照我已发布的《福彩双色球幻圆图的VBA程序(第三部分)》给出的方法,新建一个表,并将其重命名为“Data",下载双色球历年数据。
2、增加一个表,将其重命名为”篮球折线图“。
3、在”篮球折线图“这表上添加两个”滚动条“控件ScrollBar1和ScrollBar2,并按下图放置到相应的位置。
4、设置ScrollBar1”滚动条“控件属性。
5、设置ScrollBar2”滚动条“控件属性.
二、写入相关代码
1、点击”开发工具“”宏“,填写宏名”批量生成折线和篮球“,点击”创建“,在宏程序中粘贴代码。
Sheets("篮球折线图").Select
'设置表头
[A1] = "期号"
[B1] = "篮球号"
'设置列宽
Columns("A:A").Select
Selection.ColumnWidth = 10.25
Columns("B:B").Select
Selection.ColumnWidth = 5.75
Columns("C:R").Select
Selection.ColumnWidth = 2.38
'设置行高
Rows("1:1").Select
Selection.RowHeight = 18.75
Rows("2:22").Select
Selection.RowHeight = 14.25
'批量生成折线
For i = 1 To 19
If Cells(i + 1, 2).Value > Cells(i + 2, 2).Value Then
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, 100, (i - 1) * 14.25 + 27 + 14.25 / 2, 150, (i - 1) * 14.25 + 27 + 14.25 / 2).Select
Selection.Name = "Line" & i
Application.CommandBars("Format Object").Visible = False
'设置形状边框颜色——黑色
With Selection.ShapeRange.line
.Visible = msoTrue
.Weight = 0.75
.ForeColor.RGB = RGB(0, 0, 255)
.Transparency = 0
End With
End If
If Cells(i + 1, 2).Value < Cells(i + 2, 2).Value Then
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, 100, (i - 1) * 14.25 + 27 + 14.25 / 2, 150, (i - 1) * 14.25 + 27 + 14.25 / 2).Select
Selection.Name = "Line" & i
Application.CommandBars("Format Object").Visible = False
'设置形状边框颜色——黑色
With Selection.ShapeRange.line
.Visible = msoTrue
.Weight = 0.75
.ForeColor.RGB = RGB(0, 0, 255)
.Transparency = 0
End With
End If
If Cells(i + 1, 2).Value = Cells(i + 2, 2).Value Then
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, 100, (i - 1) * 14.25 + 27 + 14.25 / 2, 150, (i - 1) * 14.25 + 27 + 14.25 / 2).Select
Selection.Name = "Line" & i
Application.CommandBars("Format Object").Visible = False
'设置形状边框颜色——黑色
With Selection.ShapeRange.line
.Visible = msoTrue
.Weight = 0.75
.ForeColor.RGB = RGB(0, 0, 255)
.Transparency = 0
End With
End If
Next
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, 130, 18, 130, 300).Select
Selection.Name = "Line" & i
Application.CommandBars("Format Object").Visible = False
'设置形状边框颜色——黑色
With Selection.ShapeRange.line
.Visible = msoTrue
.Weight = 1.5
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
'批量生成篮球1
For i = 1 To 20
'在活动工作表上添加新的形状—msoShapeOval(圆形)
ActiveSheet.Shapes.AddShape(msoShapeOval, 140, 20 + (i - 1) * 14.26, 12, 12).Select
Selection.Placement = xlFreeFloating
Application.CommandBars("Format Object").Visible = False
'将形状重命名为"blueball" & i
Selection.Name = "blueball" & i
Selection.ShapeRange.TextFrame2.TextRange.Characters.Text = i
'设置形状边框颜色——黑色
With Selection.ShapeRange.line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 255)
.Transparency = 0
End With
'填充形状颜色——白色
With Selection.ShapeRange.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 255)
.Transparency = 0
.Solid
End With
Selection.ShapeRange.TextFrame2.WordWrap = msoFalse
With Selection.ShapeRange.TextFrame2
.VerticalAnchor = msoAnchorMiddle
.HorizontalAnchor = msoAnchorCenter
End With
Application.CommandBars("Format Object").Visible = False
Next
'批量生成篮球2
For i = 1 To 16
'在活动工作表上添加新的形状—msoShapeOval(圆形)
ActiveSheet.Shapes.AddShape(msoShapeOval, 89 + i * 18, 3, 12, 12).Select
Selection.Placement = xlFreeFloating
Application.CommandBars("Format Object").Visible = False
'将形状重命名为"blueball" & i
Selection.Name = "blueball" & i + 16
Selection.ShapeRange.TextFrame2.TextRange.Characters.Text = i
'设置形状边框颜色——黑色
With Selection.ShapeRange.line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 255)
.Transparency = 0
End With
'填充形状颜色——白色
With Selection.ShapeRange.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 255)
.Transparency = 0
.Solid
End With
Selection.ShapeRange.TextFrame2.WordWrap = msoFalse
With Selection.ShapeRange.TextFrame2
.VerticalAnchor = msoAnchorMiddle
.HorizontalAnchor = msoAnchorCenter
End With
Application.CommandBars("Format Object").Visible = False
Next
2,再创建一个宏,并命名为”删除所有形状“。这个运行这个宏的目的,是用户在实际运行过程中无意删除了部分折线或篮球形状(Shapes)后,点击运行这个宏,则可以恢复所有的折线和篮球形状(Shapes)。代码如下。
Dim shp As Shape
Sheets("篮球折线图").Select
For Each shp In ActiveSheet.Shapes
If shp.Type = msoConnectorStraight Then
shp.Delete
End If
Next shp
End Sub
3、向名为ScrollBar1的”滚动条“控件的Change事件粘贴代码。代码如下。
Private Sub ScrollBar1_Change()
Dim i As Integer
Dim j As Integer
'清除选定区域的数据
Range("C2:R23").Select
Selection.ClearContents
Sheets("Data").Select
'统计期数 彩票期数(Number of Lottery Periods)NoLP
Nolp = ActiveSheet.UsedRange.Rows.Count - 2
Sheets("篮球折线图").Select
ScrollBar1.Max = Nolp
ScrollBar1.Min = 3
For i = 1 To 20
Sheets("篮球折线图").Cells(i + 1, 1).Value = Sheets("Data").Cells((ScrollBar1.Value - 21) + i + 2, 1).Value & "期"
Sheets("篮球折线图").Cells(i + 1, 2).Value = Sheets("Data").Cells((ScrollBar1.Value - 21) + i + 2, 9).Value
Next
Dim shp As Shape
For i = 1 To 19
Set shp = ActiveSheet.Shapes("Line" & i)
shp.height = 0
shp.Rotation = 0
Next
For i = 1 To 19
Set shp = ActiveSheet.Shapes("Line" & i)
If Cells(i + 1, 2).Value > Cells(i + 2, 2).Value Then
shp.left = 104 + (Cells(i + 2, 2).Value - 1) * 18 + 9
shp.top = (i - 1) * 14.25 + 27 + 14.25 / 2 ' 25 + (i - 1) * 14.25 + 1
shp.width = (104 + (Cells(i + 1, 2).Value) * 18 - 9) - (104 + (Cells(i + 2, 2).Value - 1) * 18 + 9)
shp.Rotation = -180 * 7.12 / (3.14 * shp.width / 2) '近似算法,已知弧度、半径求角度
shp.width = (104 + (Cells(i + 1, 2).Value) * 18 - 9) - (104 + (Cells(i + 2, 2).Value - 1) * 18 + 9)
End If
If Cells(i + 1, 2).Value < Cells(i + 2, 2).Value Then
shp.left = 104 + (Cells(i + 1, 2).Value) * 18 - 9
shp.top = 25 + (i - 1) * 14.25 + 1
shp.width = (104 + (Cells(i + 2, 2).Value - 1) * 18 + 9) - (104 + (Cells(i + 1, 2).Value) * 18 - 9)
shp.height = 14.25
End If
If Cells(i + 1, 2).Value = Cells(i + 2, 2).Value Then
shp.left = 104 + (Cells(i + 1, 2).Value) * 18 - 9
shp.top = 25 + (i - 1) * 14.25 + 1
shp.width = 0
shp.height = 14.25
End If
Next
'篮球位置
For i = 1 To 20
Set shp = ActiveSheet.Shapes("blueball" & i)
shp.left = 124 + (Cells(i + 1, 2).Value - 2) * 18
shp.TextFrame2.TextRange.Characters.Text = Cells(i + 1, 2).Value
Next
[T2].Select
End Sub
4、向名为ScrollBar2的”滚动条“控件的Change事件粘贴代码。代码如下。
Private Sub ScrollBar2_Change()
Set shp = ActiveSheet.Shapes("Line20")
shp.left = 130 + (ScrollBar2.Value - 1) * 18
End Sub
5、点击”保存“。
6、点击”宏“,执行”批量生成折线和篮球“宏,运行结果如图。
7、点击名为ScrollBar1的”移动条“,运行结果如图。
8、点击名为ScrollBar2的”移动条“,移动红色的竖线,运行结果如图。
- 上一篇: 盘点:世界各国千奇百怪的迎新年风俗
- 下一篇: 在理论里,一个粗糙的圆,是圆么?
猜你喜欢
- 2024-12-19 C++的23种设计模式(上篇-创建型模式)
- 2024-12-19 25000 字详解 23 种设计模式(多图 + 代码)
- 2024-12-19 开源的的二维绘图引擎,EChart在用的图形渲染器——ZRender
- 2024-12-19 手机拍大片诀窍记心间 掌上PS应用合集
- 2024-12-19 搞科研常用技能和绘图学习 科研绘图工具
- 2024-12-19 「服装小知识」服装各部位名称学习(中英对照)
- 2024-12-19 10分钟教你如何看懂GIA证书 怎么看gia证书的详细信息
- 2024-12-19 图片四个角怎么能做成圆弧角?这几种制作方法操作起来很简单!
- 2024-12-19 苹果梨篇:大庙香水梨 大香水梨品种介绍
- 2024-12-19 教你用OpenCV 和 Python实现圆物检测
- 02-21走进git时代, 你该怎么玩?_gits
- 02-21GitHub是什么?它可不仅仅是云中的Git版本控制器
- 02-21Git常用操作总结_git基本用法
- 02-21为什么互联网巨头使用Git而放弃SVN?(含核心命令与原理)
- 02-21Git 高级用法,喜欢就拿去用_git基本用法
- 02-21Git常用命令和Git团队使用规范指南
- 02-21总结几个常用的Git命令的使用方法
- 02-21Git工作原理和常用指令_git原理详解
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)