AW: Bedingung für ComboBox Inhalt
09.01.2006 10:59:26
Peter
Hallo Gregor,
ich habe deine Excel-Mappe einmal versucht anzupassen (im Acivate-Ereignis).
Hier ist das Ergebnis, ich finde es funktioniert so.
Es wird die Spalte I berücksichtigt und es werden die ComboBoxes sortiert.
Du solltest das Initialize-Ereignis auflösen und in das Activate integrieren.
Private Sub UserForm_Activate()
With Application
.ScreenUpdating = False
End With
Worksheets("Daten").Visible = True
Sheets("Daten").Select
'**************Combobox füllen aus einer Tabelle
'Dim exist As Boolean
'For i = 1 To Worksheets("Daten").Cells(65536, 2).End(xlUp).Row
' exist = False
' For j = 1 To Eingabemodul.ComboBoxKreditorAlle.ListCount
' If Worksheets("Daten").Cells(i, 2).Value = _
' Eingabemodul.ComboBoxKreditorAlle.List(j - 1) Then _
' exist = True: Exit For
' Next j
' If exist = False Then _
' Eingabemodul.ComboBoxKreditorAlle.AddItem _
' Worksheets("Daten").Cells(i, 2).Value
' Next i
'**************Combobox füllen aus mehreren Tabellen
Dim aBlaetter() As Variant
Dim iIndx As Integer
Dim lZeile As Long
Dim lAnzahl As Long
Dim bExist As Boolean
Dim lIndxA As Long ' For/Next Index - außen
Dim lIndxI As Long ' For/next Index - innen
Dim sTemp1 As String ' temporärer Zwischenspeicher
Dim sTemp2 As String ' temporärer Zwischenspeicher
aBlaetter = Array("Daten")
For iIndx = 0 To UBound(aBlaetter)
For lZeile = 2 To Worksheets(aBlaetter(iIndx)).Cells(65536, 2).End(xlUp).Row
bExist = False
For lAnzahl = 1 To Eingabemodul.ComboBoxKreditorAlle.ListCount
If Worksheets(aBlaetter(iIndx)).Cells(lZeile, 2).Value = _
Eingabemodul.ComboBoxKreditorAlle.List(lAnzahl - 1) Then _
bExist = True: Exit For
Next lAnzahl
If bExist = False Then _
Eingabemodul.ComboBoxKreditorAlle.AddItem _
Worksheets(aBlaetter(iIndx)).Cells(lZeile, 2).Value
Next lZeile
Next iIndx
' Combobox sortieren : alphabetisch, aufsteigend - bei einspaltiger ComboBox
For lIndxA = 0 To Me.ComboBoxKreditorAlle.ListCount - 1
For lIndxI = 0 To lIndxA - 1
If Me.ComboBoxKreditorAlle.List(lIndxI) > Me.ComboBoxKreditorAlle.List(lIndxA) Then
sTemp1 = Me.ComboBoxKreditorAlle.List(lIndxI)
Me.ComboBoxKreditorAlle.List(lIndxI) = Me.ComboBoxKreditorAlle.List(lIndxA)
Me.ComboBoxKreditorAlle.List(lIndxA) = sTemp1
End If
Next lIndxI
Next lIndxA
Dim zl As Long
Dim lCoBo As Long
last_index = -1
ComboBoxKreditorÄnd.Clear
zl = START_ZEILE
While Cells(zl, "A").Value <> "" 'And Cells(zl, "I").Value <> 0
If IsEmpty(Cells(zl, "I").Value) Then
ComboBoxKreditorÄnd.AddItem
ComboBoxKreditorÄnd.List(lCoBo, 0) = Cells(zl, "B").Value
ComboBoxKreditorÄnd.List(lCoBo, 1) = Cells(zl, "A").Value
lCoBo = lCoBo + 1
End If
zl = zl + 1
Wend
' ComboBox sortieren : alphabetisch, aufsteigend - bei zweispaltiger ComboBox
For lIndxA = 0 To Me.ComboBoxKreditorÄnd.ListCount - 1
For lIndxI = 0 To lIndxA - 1
If Me.ComboBoxKreditorÄnd.List(lIndxI, 0) > Me.ComboBoxKreditorÄnd.List(lIndxA, 0) Then
sTemp1 = Me.ComboBoxKreditorÄnd.List(lIndxI, 0)
sTemp2 = Me.ComboBoxKreditorÄnd.List(lIndxI, 1)
Me.ComboBoxKreditorÄnd.List(lIndxI, 0) = Me.ComboBoxKreditorÄnd.List(lIndxA, 0)
Me.ComboBoxKreditorÄnd.List(lIndxI, 1) = Me.ComboBoxKreditorÄnd.List(lIndxA, 1)
Me.ComboBoxKreditorÄnd.List(lIndxA, 0) = sTemp1
Me.ComboBoxKreditorÄnd.List(lIndxA, 1) = sTemp2
End If
Next lIndxI
Next lIndxA
If Selection.Row >= START_ZEILE _
And Selection.Row < zl - 1 Then _
ComboBoxKreditorÄnd.ListIndex = Selection.Row - START_ZEILE
End Sub
Viele Grüße Peter
Eine kurze Nachricht, ob es läuft, wäre nett - danke.