ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1563|回复: 4

[求助]数字组合问题

[复制链接]

TA的精华主题

TA的得分主题

发表于 2007-8-10 11:58 | 显示全部楼层 |阅读模式

我不会编程,高手帮忙解决一下:请教一下有两组数据,假设A组为1-33中的任意15个数字,B组为1-16中的任意10个数字;这些数据已经存在;怎样从A组的15个数字中提取6个数字组合,不要求排序,然后B组中提取1个数字同A组组合成7个数字;最后批量输出为文本文件。实际上就是双色球的批量复式转单式,由于找不到工具,只好求助高手!

TA的精华主题

TA的得分主题

发表于 2007-8-10 13:29 | 显示全部楼层

欢迎lw0851朋友

Sub seq()
Application.ScreenUpdating = False
Dim x As New Collection, a(1 To 15), b(1 To 10), x1, x2, x3, x4, x5, x6, x7, n, arr()
Randomize
For x1 = 1 To 33
x.Add x1
Next
For x1 = 1 To 15
x2 = 1 + Int(Rnd * x.Count)
a(x1) = x(x2)
x.Remove x2
Next

Set x = Nothing
For x1 = 1 To 16
x.Add x1
Next
For x1 = 1 To 10
x2 = 1 + Int(Rnd * x.Count)
b(x1) = x(x2)
x.Remove x2
Next

ReDim arr(1 To 10 * WorksheetFunction.Combin(15, 6), 1 To 1)
For x1 = 1 To 10
For x2 = x1 + 1 To 11
For x3 = x2 + 1 To 12
For x4 = x3 + 1 To 13
For x5 = x4 + 1 To 14
For x6 = x5 + 1 To 15
For x7 = 1 To 10
n = n + 1
arr(n, 1) = a(x1) & "," & a(x2) & "," & a(x3) & "," & a(x4) & "," & a(x5) & "," & a(x6) & "---" & b(x7)
Next x7, x6, x5, x4, x3, x2, x1

[a1] = "A组:" & Join(a, ",")
[a2] = "B组:" & Join(b, ",")
[a4].Resize(n, 1) = arr
[A:A].Columns.AutoFit
Application.ScreenUpdating = True
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2007-8-10 14:30 | 显示全部楼层

谢谢版主回复

请帮我看一下,这个文件的数据该怎样做到批量复式转单式输出,对于编程一窍不通,看不懂,见笑了! fC51VVIr.rar (27.28 KB, 下载次数: 24)

TA的精华主题

TA的得分主题

 楼主| 发表于 2007-8-10 17:22 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
请northwolves帮忙看看文件

TA的精华主题

TA的得分主题

发表于 2007-8-10 17:39 | 显示全部楼层

try:

Sub seq()
Dim arr, x0&, x1&, x2&, x3&, x4&, x5&, x6&, x7&, n&, s() As String
arr = [a1].CurrentRegion
ReDim s(1 To 50050 * UBound(arr))
For x0 = 1 To UBound(arr)
For x1 = 1 To 10
For x2 = x1 + 1 To 11
For x3 = x2 + 1 To 12
For x4 = x3 + 1 To 13
For x5 = x4 + 1 To 14
For x6 = x5 + 1 To 15
For x7 = 17 To 26
n = n + 1
s(n) = arr(x0, x1) & "," & arr(x0, x2) & "," & arr(x0, x3) & "," & arr(x0, x4) & "," & arr(x0, x5) & "," & arr(x0, x6) & "---" & arr(x0, x7)
Next x7, x6, x5, x4, x3, x2, x1, x0
Open "d:\result.txt" For Binary As #1
Put #1, , Join(s, vbCrLf)
Close #1
MsgBox "ok"
End Sub

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-23 14:55 , Processed in 0.027019 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表