標題:
[發問]
在vba userform 設3個 combox3 如何3層篩選
[打印本頁]
作者:
user999
時間:
2011-10-28 07:54
標題:
在vba userform 設3個 combox3 如何3層篩選
在vba userform 設3個 combox3
資料來源 EXCEL SHEET1 分類:A欄 大項 B欄 小項C欄 細項 D欄 所要的值
這超個1層要如何寫,請教各位先進,謝謝!
作者:
user999
時間:
2011-10-28 14:37
回復
1#
user999
再
再麻煩您看看 我還沒權限 下載
作者:
oobird
時間:
2011-10-28 15:35
userform中:
Private Sub ComboBox1_Change()
With ComboBox2
If InStr(d(ComboBox1.Value), ",") = 0 Then
.Clear
.AddItem d(ComboBox1.Value)
Else
.List = Split(d(ComboBox1.Value), ",")
End If
End With
End Sub
Private Sub ComboBox2_Change()
With ComboBox3
If InStr(d2(ComboBox1.Value & ComboBox2.Value), ",") = 0 Then
.Clear
.AddItem d2(ComboBox1.Value & ComboBox2.Value)
Else
.List = Split(d2(ComboBox1.Value & ComboBox2.Value), ",")
End If
End With
End Sub
Private Sub ComboBox3_Change()
With Sheet1
rng = .UsedRange
For i = 2 To UBound(rng)
If rng(i, 1) & rng(i, 2) & rng(i, 3) = ComboBox1.Value & ComboBox2.Value & ComboBox3.Value Then
x = x + rng(i, 4)
End If
Next
TextBox1.Value = x
End With
End Sub
Private Sub UserForm_Initialize()
Set d = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")
With Sheet1
rng = .UsedRange
For i = 2 To UBound(rng)
If d(rng(i, 1)) = "" Then
d(rng(i, 1)) = rng(i, 2)
Else
If InStr(d(rng(i, 1)), rng(i, 2)) = 0 Then
d(rng(i, 1)) = d(rng(i, 1)) & "," & rng(i, 2)
End If
End If
If d2(rng(i, 1) & rng(i, 2)) = "" Then
d2(rng(i, 1) & rng(i, 2)) = rng(i, 3)
Else
If InStr(d2(rng(i, 1) & rng(i, 2)), rng(i, 3)) = 0 Then
d2(rng(i, 1) & rng(i, 2)) = d2(rng(i, 1) & rng(i, 2)) & "," & rng(i, 3)
End If
End If
Next
ComboBox1.List = d.keys
End With
End Sub
複製代碼
Module中
Public d As Object
Public d2 As Object
複製代碼
作者:
GBKEE
時間:
2011-10-28 15:46
回復
2#
user999
UserForm 的程式碼
Dim D As Object
Private Sub UserForm_Initialize()
Dim Dx(1 To 3) As Object, i As Integer, ii As Integer
Set D = CreateObject("SCRIPTING.DICTIONARY")
For ii = 1 To UBound(Dx)
Set Dx(ii) = CreateObject("SCRIPTING.DICTIONARY")
Next
i = 2
Do While Sheet1.Cells(i, 1) <> ""
For ii = 1 To UBound(Dx)
Dx(ii)(Cells(i, ii).Value) = ""
Next
D(Cells(i, 1) & Cells(i, 2) & Cells(i, 3)) = Cells(i, "d")
i = i + 1
Loop
For ii = 1 To UBound(Dx)
Controls("ComboBox" & ii).List = Dx(ii).keys
Next
End Sub
Private Sub ComboBox1_Change()
平均
End Sub
Private Sub ComboBox2_Change()
平均
End Sub
Private Sub ComboBox3_Change()
平均
End Sub
Private Sub 平均()
If D.exists(ComboBox1 & ComboBox2 & ComboBox3) Then
TextBox1 = D(ComboBox1 & ComboBox2 & ComboBox3)
Else
TextBox1 = ""
End If
End Sub
複製代碼
作者:
user999
時間:
2011-10-28 17:23
回復
3#
oobird
太感謝您們了!我該好好學習,以您們為榜樣,熱心專業,謝謝!
作者:
user999
時間:
2011-10-28 17:27
回復
4#
GBKEE
太感謝您們了!我該好好學習,以您們為榜樣,熱心專業,謝謝!
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)