Ive solved this.
Here is the code if somebody wants.
Private Sub CommandButton1_Click()
Unload UserForm1
End Sub
Private Sub ComboBox4_Change()
End Sub
Private Sub UserForm_Initialize()
'Load UserForm1
Osakond Range([A2], [A2].End(xlDown))
End Sub
Sub Osakond(Data As Range)
Dim d, cel As Range
Set d = CreateObject("Scripting.Dictionary")
For Each cel In Data
On Error Resume Next
d.Add cel.Text, cel.Text
Next
ComboBox1.List() = d.items
End Sub
Private Sub ComboBox1_Change()
ComboBox2.Clear
AddExtras Range([D2], [D2].End(xlDown))
Artikkel Range([B2], [B2].End(xlDown))
End Sub
Sub AddExtras(Data As Range)
Dim d, cel As Range
Set d = CreateObject("Scripting.Dictionary")
For Each cel In Data
If cel.Offset(, -3) = ComboBox1.Text Then
On Error Resume Next
d.Add cel.Text, cel.Text
End If
Next
ListBox1.List = d.items
Dim sum As Integer
Dim cnt As Integer
Dim n As Integer
n = ListBox1.ListCount
For cnt = 0 To n - 1
sum = sum + ListBox1.List(cnt)
Next cnt
TextBox1.Text = sum
End Sub
Sub Artikkel(Data As Range)
Dim d, cel As Range
Set d = CreateObject("Scripting.Dictionary")
For Each cel In Data
If cel.Offset(, -1) = ComboBox1.Text Then
On Error Resume Next
d.Add cel.Text, cel.Text
End If
Next
ComboBox2.List() = d.items
End Sub
Private Sub ComboBox2_Change()
ComboBox3.Clear
ListBox1.Clear
AddExtras1 Range([D2], [D2].End(xlDown))
Object Range([C2], [C2].End(xlDown))
End Sub
Sub AddExtras1(Data As Range)
Dim d, cel As Range
Set d = CreateObject("Scripting.Dictionary")
For Each cel In Data
If cel.Offset(, -2) = ComboBox2.Text And _
cel.Offset(, -3).Text = ComboBox1.Text Then
On Error Resume Next
d.Add cel.Text, cel.Text
End If
Next
ListBox1.List = d.items
Dim sum As Integer
Dim cnt As Integer
Dim n As Integer
n = ListBox1.ListCount
For cnt = 0 To n - 1
sum = sum + ListBox1.List(cnt)
Next cnt
TextBox1.Text = sum
End Sub
Sub Object(Data As Range)
Dim d, cel As Range
Set d = CreateObject("Scripting.Dictionary")
For Each cel In Data
If cel.Offset(, -1) = ComboBox2.Text And cel.Offset(, -2).Text = ComboBox1.Text Then
On Error Resume Next
d.Add cel.Text, cel.Text
End If
Next
ComboBox3.List() = d.items
End Sub
Private Sub ComboBox3_Change()
ListBox1.Clear
AddExtras2 Range([D2], [D2].End(xlDown))
End Sub
Sub AddExtras2(Data As Range)
Dim d, cel As Range
Set d = CreateObject("Scripting.Dictionary")
For Each cel In Data
If cel.Offset(, -1) = ComboBox3.Text And cel.Offset(, -2) = ComboBox2.Text _
And cel.Offset(, -3) = ComboBox1.Text Then
On Error Resume Next
d.Add cel.Text, cel.Text
End If
Next
ListBox1.List = d.items
Dim sum As Integer
Dim cnt As Integer
Dim n As Integer
n = ListBox1.ListCount
For cnt = 0 To n - 1
sum = sum + ListBox1.List(cnt)
Next cnt
TextBox1.Text = sum
End Sub
Now trying to find out how to allow choosing the second combobox if the first one is not chosen.
Bookmarks