Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1474|回复: 3

[已解决]请老师修改代码

[复制链接]
发表于 2013-3-19 16:02 | 显示全部楼层 |阅读模式
请老师修改代码。谢谢
最佳答案
2013-3-19 16:38
  1. Private Sub 组合_Click()

  2.     Dim Arr, i&, r%, s(), j&, i1&, i2&, i3&, i4&, i5&, x$, x3%
  3.     Dim d, k, Brr
  4.     Range("a4:ce14") = ""
  5.     Set d = CreateObject("Scripting.Dictionary")

  6.     For x3 = 0 To 3
  7.         Arr = Range(Cells(1, 1 + x3 * 14), Cells(2, 7 + x3 * 14))
  8.         Debug.Print Range(Cells(1, 1 + x3 * 14), Cells(2, 7 + x3 * 14)).Address(False, False)
  9.         For i = 1 To UBound(Arr)

  10.             For j = 1 To UBound(Arr, 2)

  11.                 If Arr(i, j) <> "" Then

  12.                     r = r + 1

  13.                     ReDim Preserve s(1 To r)

  14.                     s(r) = Arr(i, j)

  15.                 End If

  16.             Next

  17.             If r >= 5 Then

  18.                 For i1 = 1 To r - 4

  19.                     For i2 = i1 + 1 To r - 3

  20.                         For i3 = i2 + 1 To r - 2

  21.                             For i4 = i3 + 1 To r - 1

  22.                                 For i5 = i4 + 1 To r

  23.                                     x = s(i1) & "," & s(i2) & "," & s(i3) & "," & s(i4) & "," & s(i5)

  24.                                     d(x) = ""

  25.                                 Next

  26.                             Next

  27.                         Next

  28.                     Next

  29.                 Next

  30.             End If

  31.             r = 0

  32.         Next

  33.         k = d.keys

  34.         ReDim Brr(1 To d.Count, 1 To 7)

  35.         For i = 0 To UBound(k)

  36.             aa = Split(k(i), ",")

  37.             For j = 0 To UBound(aa)

  38.                 Brr(i + 1, aa(j)) = aa(j)

  39.             Next

  40.         Next

  41.         Cells(4, 1 + x3 * 14).Resize(UBound(Brr), 7) = Brr
  42.         d.RemoveAll

  43.     Next x3
  44. End Sub
复制代码

组合.rar

27.03 KB, 下载次数: 10

发表于 2013-3-19 16:37 | 显示全部楼层
  1. Cells(4, 1 + x3 * 14).Resize(UBound(Brr), 7) = Brr
  2. d.RemoveAll
复制代码
每次得清空字典。
回复

使用道具 举报

发表于 2013-3-19 16:38 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub 组合_Click()

  2.     Dim Arr, i&, r%, s(), j&, i1&, i2&, i3&, i4&, i5&, x$, x3%
  3.     Dim d, k, Brr
  4.     Range("a4:ce14") = ""
  5.     Set d = CreateObject("Scripting.Dictionary")

  6.     For x3 = 0 To 3
  7.         Arr = Range(Cells(1, 1 + x3 * 14), Cells(2, 7 + x3 * 14))
  8.         Debug.Print Range(Cells(1, 1 + x3 * 14), Cells(2, 7 + x3 * 14)).Address(False, False)
  9.         For i = 1 To UBound(Arr)

  10.             For j = 1 To UBound(Arr, 2)

  11.                 If Arr(i, j) <> "" Then

  12.                     r = r + 1

  13.                     ReDim Preserve s(1 To r)

  14.                     s(r) = Arr(i, j)

  15.                 End If

  16.             Next

  17.             If r >= 5 Then

  18.                 For i1 = 1 To r - 4

  19.                     For i2 = i1 + 1 To r - 3

  20.                         For i3 = i2 + 1 To r - 2

  21.                             For i4 = i3 + 1 To r - 1

  22.                                 For i5 = i4 + 1 To r

  23.                                     x = s(i1) & "," & s(i2) & "," & s(i3) & "," & s(i4) & "," & s(i5)

  24.                                     d(x) = ""

  25.                                 Next

  26.                             Next

  27.                         Next

  28.                     Next

  29.                 Next

  30.             End If

  31.             r = 0

  32.         Next

  33.         k = d.keys

  34.         ReDim Brr(1 To d.Count, 1 To 7)

  35.         For i = 0 To UBound(k)

  36.             aa = Split(k(i), ",")

  37.             For j = 0 To UBound(aa)

  38.                 Brr(i + 1, aa(j)) = aa(j)

  39.             Next

  40.         Next

  41.         Cells(4, 1 + x3 * 14).Resize(UBound(Brr), 7) = Brr
  42.         d.RemoveAll

  43.     Next x3
  44. End Sub
复制代码
回复

使用道具 举报

发表于 2013-3-19 16:39 | 显示全部楼层
  1. ReDim Brr(1 To d.Count, 1 To 7)
复制代码
你在这一句设断点,单步后就会发现,后面数组维数不同嘛。
回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-19 06:41 , Processed in 0.270626 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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