|
楼主 |
发表于 2012-2-13 23:25
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
尊敬的高手:经过你的指点,我知道错误在第二长表的初始赋值上,经过思考我认为程序是不是能够这样写?,当接近1048576行时将输出结果输出到第二张表上,
故在程序开始设置一个行计数变量,但是程序运行好像进入死循环,不知道错在哪里,顺便告诉高手那句 If a = b Then b = b + 1 好像有必要,我就是看见生成的
数据中有 1,2,3,4,6,6 才写的,我的程序如下,烦高手赐教:
Sub combin_33_6()
Dim a, b, c, d, e, f As Integer
Dim thecell As Range
Dim i As Long
i = 0
Sheets("sheet1").Select
Set thecell = Range("a1")
For a = 1 To 28 'a最小为1
For b = a + 1 To 29 'b最小为2
If a = b Then b = b + 1
For c = b + 1 To 30 'c最小为3
If b = c Then c = c + 1
For d = c + 1 To 31 'd最小为4
If c = d Then d = d + 1
For e = d + 1 To 32 'e最小为5
If d = e Then e = e + 1
For f = e + 1 To 33 'f最小为6
If e = f Then f = f + 1
i = i + 1
If i < 1048575 Then
thecell.Value = a
Set thecell = thecell.Offset(0, 1) ' 移位
thecell.Value = b
Set thecell = thecell.Offset(0, 1)
thecell.Value = c
Set thecell = thecell.Offset(0, 1)
thecell.Value = d
Set thecell = thecell.Offset(0, 1)
thecell.Value = e
Set thecell = thecell.Offset(0, 1)
thecell.Value = f
Set thecell = thecell.Offset(1, -5) ' 重新定位,换行换列
Else
Sheets("sheet2").Select
Set thecell = Range("a1")
thecell.Value = a
Set thecell = thecell.Offset(0, 1) ' 移位
thecell.Value = b
Set thecell = thecell.Offset(0, 1)
thecell.Value = c
Set thecell = thecell.Offset(0, 1)
thecell.Value = d
Set thecell = thecell.Offset(0, 1)
thecell.Value = e
Set thecell = thecell.Offset(0, 1)
thecell.Value = f
Set thecell = thecell.Offset(1, -5) ' 重新定位,换行换列
End If
Next f
Next e
Next d
Next c
Next b
Next a
End Sub
不知道什么原因,程序运行很久,无法结束?
|
|