返回列表 上一主題 發帖

如何利用勾選方塊來篩選資料

如何利用勾選方塊來篩選資料

想請問各位大大
我現在想要利用表單篩選資料

下拉式選擇資料還可以執行
但如果想要利用勾選資料的方式
不曉得問題點在哪裡 ><
測試.zip (18.57 KB)
  1. Dim a, b, c, d, e, f, g, h, i, j, k, l, m
  2. Private Sub CommandButton1_Click() '篩選條件

  3. a = Test.ComboBox1.Value '季節
  4. b = Test.ComboBox2.Value '月份

  5. d = CheckBox1.Value
  6. e = CheckBox2.Value
  7. f = CheckBox3.Value
  8. g = CheckBox4.Value
  9. h = CheckBox5.Value
  10. i = CheckBox6.Value
  11. j = CheckBox7.Value
  12. k = CheckBox8.Value
  13. l = CheckBox9.Value
  14. m = CheckBox10.Value

  15. c = Array(d, e, f, g, h, i, j, k, l, m)


  16. With ActiveSheet.Range("$A$1:$K$121")
  17.     .Parent.AutoFilterMode = False   '顯示全部資料 ->新的 多重篩選
  18.    
  19.     '多重篩選  ..........
  20.     If a <> "" Then .AutoFilter Field:=1, Criteria1:=a
  21.     If b <> "" Then .AutoFilter Field:=2, Criteria1:=b
  22.     If c <> "" Then .AutoFilter Field:=3, Criteria1:=c, Operator:=xlFilterValues
  23.     '多重篩選  ..........
  24. End With
  25. End Sub

  26. Private Sub CommandButton2_Click() '清除內容
  27. Me.ComboBox1 = ""
  28. Me.ComboBox2 = ""
  29. Me.CheckBox1 = ""
  30. Me.CheckBox2 = ""
  31. Me.CheckBox3 = ""
  32. Me.CheckBox4 = ""
  33. Me.CheckBox5 = ""
  34. Me.CheckBox6 = ""
  35. Me.CheckBox7 = ""
  36. Me.CheckBox8 = ""
  37. Me.CheckBox9 = ""
  38. Me.CheckBox10 = ""
  39. End Sub

  40. Private Sub CommandButton3_Click() '取消
  41. Test.Hide
  42. End Sub

  43. Private Sub CommandButton4_Click() '展開
  44. ActiveSheet.Range("$A$1:$K$121").AutoFilter Field:=1
  45. ActiveSheet.Range("$A$1:$K$121").AutoFilter Field:=2
  46. ActiveSheet.Range("$A$1:$K$121").AutoFilter Field:=3
  47. End Sub
  48. Private Sub UserForm_Initialize()

  49.     ComboBox1.List = Array("Q1", "Q2", "Q3", "Q4") '季
  50.    
  51.     ComboBox2.List = Array("一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月") '月

  52. End Sub
複製代碼
Jared

回復 2# luhpro


    謝謝大大 :)
Jared

TOP

        靜思自在 : 一句溫暖的話,就像往別人身上灑香水,自己會沾到兩三滴。
返回列表 上一主題