Excel精英培训网

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

[已解决]修改提取代码

[复制链接]
发表于 2013-12-5 12:04 | 显示全部楼层 |阅读模式
本帖最后由 c888 于 2013-12-5 13:22 编辑

窗体数据提取(翻页).rar (15.15 KB, 下载次数: 10)
发表于 2013-12-5 13:03 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub ComboBox1_Change()
  2.     CommandButton1.Enabled = False
  3.     For i = 1 To 30
  4.         Controls("Label" & i).Caption = ""
  5.     Next
  6.     Set d = CreateObject("scripting.dictionary")
  7.     With Sheets("3")
  8.         HX = .Range("a65536").End(xlUp).Row
  9.         arr = .Range("a2:c" & HX)
  10.     End With
  11.     If b Then Exit Sub
  12.     n = 0
  13.     For i = 1 To UBound(arr)
  14.         If arr(i, 3) = ComboBox1.Value Then
  15.             n = n + 1
  16.             ReDim Preserve arr2(1 To 3, 1 To n)
  17.             For j = 1 To 3
  18.                 arr2(j, n) = arr(i, j)
  19.             Next
  20.         End If
  21.     Next
  22.     If n >= 10 Then CommandButton1.Enabled = True
  23.     n = 1
  24.     cyj
  25. End Sub

  26. Private Sub CommandButton1_Click()
  27.     For i = 1 To 30
  28.         Controls("Label" & i).Caption = ""
  29.     Next
  30.     If n > UBound(arr2, 2) Then n = 1
  31.     cyj
  32. End Sub

  33. Private Sub UserForm_Initialize()
  34.     Set d = CreateObject("scripting.dictionary")
  35.     With Sheets("3")
  36.         HX = .Range("a65536").End(xlUp).Row
  37.         arr = .Range("a2:c" & HX)
  38.     End With
  39.     For x = 1 To UBound(arr)
  40.         If Not d.exists(arr(x, 3)) Then d.Add arr(x, 3), ""
  41.     Next
  42.     Me.ComboBox1.Clear
  43.     Me.ComboBox1.List = d.keys
  44. End Sub

  45. Sub cyj()
  46.     Do Until k = 10 Or n > UBound(arr2, 2)
  47.         k = k + 1
  48.         Controls("Label" & k).Caption = arr2(1, n)
  49.         Controls("Label" & k + 10).Caption = arr2(2, n)
  50.         Controls("Label" & k + 20).Caption = arr2(3, n)
  51.         n = n + 1
  52.     Loop

  53. End Sub
复制代码
回复

使用道具 举报

发表于 2013-12-5 13:04 | 显示全部楼层
具体改哪我忘了,楼主自己测试下吧。
回复

使用道具 举报

发表于 2013-12-5 13:07 | 显示全部楼层
  1. Private Sub CommandButton1_Click()
  2.     For i = 1 To 30
  3.         Controls("Label" & i).Caption = ""
  4.     Next
  5.     If n > UBound(arr2, 2) Then n = 1
  6.     cyj
  7. End Sub
复制代码
就改了一句 :   If n= > UBound(arr2, 2) Then n = 1,这是你原来的。
回复

使用道具 举报

 楼主| 发表于 2013-12-5 13:21 | 显示全部楼层
hwc2ycy 发表于 2013-12-5 13:04
具体改哪我忘了,楼主自己测试下吧。

If n >= UBound(arr2, 2) Then n = 1 改为 If n > UBound(arr2, 2) Then n = 1谢谢!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 12:27 , Processed in 0.149098 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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