Office中国论坛/Access中国论坛
标题:
求助用VBA提取符合条件的数据组合
[打印本页]
作者:
www96
时间:
2012-8-21 13:25
标题:
求助用VBA提取符合条件的数据组合
求助用VBA提取符合条件的数据组合,谢谢![attach]50203[/attach]
作者:
roych
时间:
2012-8-21 21:47
本帖最后由 roych 于 2012-8-21 21:49 编辑
俺觉得你把问题复杂化了,先附上代码(写入Sheet1里):
Sub test()
Dim s(1 To 6), P(1 To 4)
Dim i, j, k, l
'分解组合第一个数组
For i = 1 To 6
s(i) = Range("B5").Offset(0, i - 1)
Next
For i = 1 To 6
For j = i + 1 To 6
For k = j + 1 To 6
a = a & "," & s(i) & ":" & s(j) & ":" & s(k)
Next
Next
Next
c = Split(a, ",")
'分解组合第二个数组
For i = 1 To 4
P(i) = Range("L5").Offset(0, i - 1)
Next
For i = 1 To 4
For j = i + 1 To 4
For k = j + 1 To 4
b = b & "," & P(i) & ":" & P(j) & ":" & P(k)
Next
Next
Next
d = Split(b, ",")
'合并两个组合
For i = 1 To UBound(d)
For j = 1 To UBound(c)
e = e & "," & c(j) & ":" & d(i)
Next
Next
f = Split(e, ",")
'写入数据
For i = 1 To UBound(f)
Range("w" & i + 1) = f(i)
Next
End Sub
复制代码
当然,代码可以更简化些许,不过个人觉得这样写的好处在于可以让大家理清思路。
[attach]50205[/attach]
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3