ich mache gerade meine ersten Gehversuche in VBA.
Ich möchte ein Auswahlmenü zu einer Tabelle mit 7 Spalten machen (Die ersten 3 Spalten sollen die Werte für das Auswahlmenü liefern)
Dazu habe ich mir eine ähnliche Beispieldatei heruntergeladen und versucht, diese anzupassen:
http://www.excel-werkstatt.de/index.php?site=download/download&kat=14&anzeigedl=16
Mein Code sieht wie folgt aus:
Private Sub ComboBox1_Change()
ComboBox2.Clear
ComboBox3.Clear
On Error Resume Next
For iRow = 2 To aRow
col.Add Cells(iRow, 2), Cells(iRow, 2)
If Err = 0 And Cells(iRow, 1) = ComboBox1.Value Then
ComboBox2.AddItem Cells(iRow, 2)
Else
Err.Clear
End If
Next iRow
On Error GoTo 0
For x = col.Count To 1 Step -1
col.Remove (x)
Next x
End Sub
Private Sub ComboBox2_Change()
ComboBox3.Clear
On Error Resume Next
For iRow = 2 To aRow
col.Add Cells(iRow, 3), Cells(iRow, 3)
If Err = 0 And Cells(iRow, 2) = ComboBox2.Value Then
ComboBox3.AddItem Cells(iRow, 3)
Else
Err.Clear
End If
Next iRow
On Error GoTo 0
For x = col.Count To 1 Step -1
col.Remove (x)
Next x
End Sub
Private Sub ComboBox3_Change()
ComboBox4.Clear
On Error Resume Next
For iRow = 2 To aRow
col.Add Cells(iRow, 4), Cells(iRow, 4)
If Err = 0 And Cells(iRow, 3) = ComboBox3.Value Then
For x = 4 To 6
Cells(3, x + 3) = Cells(iRow, x)
Next x
Else
Err.Clear
End If
Next iRow
On Error GoTo 0
For x = col.Count To 1 Step -1
col.Remove (x)
Next x
End Sub
Private Sub UserForm_Initialize()
aRow = IIf(IsEmpty(Range("A65536")), Range("A65536").End(xlUp).Row, 65536)
On Error Resume Next
For iRow = 2 To aRow
col.Add Cells(iRow, 1), Cells(iRow, 1)
If Err = 0 And Cells(iRow, 1).Value "TOTAL" Then
ComboBox1.AddItem Cells(iRow, 1)
Else
Err.Clear
End If
Next iRow
On Error GoTo 0
End Sub
Mit den Originalwerten (erweitert um 3 Spalten) der Tabelle funktioniert auch alles so, wie es soll. Füge ich allerdings jetzt meine Tabelle ein, bekomme ich nur in der ersten ComboBox eine Auswahl und in den darauf folgenden nicht.
Ich hoffe, ihr könnt mir da weiterhelfen.