Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
716to720
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
716to720
716to720
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Bedingung für ComboBox Inhalt

Bedingung für ComboBox Inhalt
08.01.2006 19:27:25
GregorJ
Hallo,
mit diesem Script wird die ComboBoxKreditorÄnd gefüllt, mit Daten aus Spalte B und A
ich möchte aber gern nur die Einträge, bei denen die Spalte I leer ist.
***************************************************************************
...
Dim zl As Long
last_index = -1
ComboBoxKreditorÄnd.Clear
zl = START_ZEILE
While Cells(zl, "A").Value ""
ComboBoxKreditorÄnd.AddItem
ComboBoxKreditorÄnd.List(zl - START_ZEILE, 0) = Cells(zl, "B").Value
ComboBoxKreditorÄnd.List(zl - START_ZEILE, 1) = Cells(zl, "A").Value
zl = zl + 1
Wend
If Selection.Row >= START_ZEILE _
And Selection.Row ComboBoxKreditorÄnd.ListIndex = Selection.Row - START_ZEILE
...
***************************************************************************
Gregor

14
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Bedingung für ComboBox Inhalt
08.01.2006 20:25:58
Peter
Hallo Gregor,
so sollte es gehen:
While Cells(zl, "A").Value ""
If IsEmpty(Cells(zl, I).Value) Then
ComboBoxKreditorÄnd.AddItem
ComboBoxKreditorÄnd.List(zl - START_ZEILE, 0) = Cells(zl, "B").Value
ComboBoxKreditorÄnd.List(zl - START_ZEILE, 1) = Cells(zl, "A").Value
zl = zl + 1
End If
Wend
Viele Grüße Peter
Eine kurze Nachricht, ob es läuft, wäre nett - danke.
AW: Bedingung für ComboBox Inhalt
08.01.2006 20:27:42
Berber
Hallo,
erweitere Deine while Bedingung
While Cells(zl, "A").Value "" and cells(zl, "I").value = ""
Tip: Verwende besser Cells(zl, 1) für Spalte A und Cells(zl, 2) für Spalte B
Gruss
Berber
Anzeige
AW: Bedingung für ComboBox Inhalt
08.01.2006 21:09:29
Gregor
Hallo Peter,
ich habe dein Vorschlag getestet, doch dann Hängt sich das Formular auf.
Es funktioniert nicht, auch nicht wenn ich, (zl, "I") schreibe.
Hallo Berber,
ich habe auch deinen Vorschlag getestet, das geht schon fast,
doch sobalt die erste Situation zutrifft, bleibt die Funktion stehen,
also wenn in den ersten beiden Spalten die Zelle I leer ist und die dritte voll,
werden nur die ersten zwei angezeigt, was nach der dritten kommt ist nicht da.
Danke noch für deinen Tip, doch das ist so beabsichtigt, damit der Nahme in Spalte B
zuerst angezeigt wird.
Danke Peter und Berber für die schnelle Reaktion
Greg
Anzeige
AW: Bedingung für ComboBox Inhalt
08.01.2006 21:22:05
Peter
Hallo Gregor,
dann versuch folgendes:
While Cells(zl, "A").Value ""
If IsEmpty(Cells(zl, 9).Value) Then
ComboBoxKreditorÄnd.AddItem
ComboBoxKreditorÄnd.List(zl - START_ZEILE, 0) = Cells(zl, "B").Value
ComboBoxKreditorÄnd.List(zl - START_ZEILE, 1) = Cells(zl, "A").Value
zl = zl + 1
End If
Wend
Viele Grüße Peter
Eine kurze Nachricht, ob es läuft, wäre nett - danke.
AW: Bedingung für ComboBox Inhalt
08.01.2006 21:36:13
GregorJ
:)
Ja das habe ich auch schon versucht,
vielleicht liegt das am weiteren Verlauf,
**********
...
Dim zl 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(zl - START_ZEILE, 0) = Cells(zl, "B").Value
ComboBoxKreditorÄnd.List(zl - START_ZEILE, 1) = Cells(zl, "A").Value
zl = zl + 1
'End If
Wend
If Selection.Row >= START_ZEILE _
And Selection.Row ComboBoxKreditorÄnd.ListIndex = Selection.Row - START_ZEILE
End Sub
...
********************
Ich habe mal die Datei hochgeladen
https://www.herber.de/bbs/user/29837.xls
Gregor
Anzeige
AW: Bedingung für ComboBox Inhalt
08.01.2006 21:43:14
Peter
Hallo Gregor,
ich habe eben deine Excel-Mappe in groben Zügen nachgebaut.
So läuft es bei mir:

Private Sub UserForm_Activate()
Dim zl  As Integer
Dim START_ZEILE  As Integer: START_ZEILE = 3
Dim iCoBO  As Integer
ComboBoxKreditorÄnd.Clear
zl = START_ZEILE
While Cells(zl, "A").Value <> ""
If IsEmpty(Cells(zl, 9).Value) Then
ComboBoxKreditorÄnd.AddItem
ComboBoxKreditorÄnd.List(iCoBO, 0) = Cells(zl, "B").Value
ComboBoxKreditorÄnd.List(iCoBO, 1) = Cells(zl, "A").Value
iCoBO = iCoBO + 1
End If
zl = zl + 1
Wend
End Sub

Das heißt, ich habe zum Füllen der ComboBox einen eigenen Index iCoBo definiert, der nach dem Eintrag der Werte in die Box hochegzählt wird.
Viele Grüße Peter
Eine kurze Nachricht, ob es läuft, wäre nett - danke.
Anzeige
AW: Bedingung für ComboBox Inhalt
08.01.2006 22:09:30
GregorJ
Danke Peter,
das funktioniert schon fast,
doch nicht unter
Private Sub UserForm_Activate()
da kommt nx,
ich habe die sowiso unter
Private Sub UserForm_Activate()
da mit eingebaut klappts fast,
es geht gut bis zum Zweiten "mannfred"
der hat die Nummer 1 und dann werden die Daten von "mannfred" Nr. 41 übernommen
Gregor
AW: Bedingung für ComboBox Inhalt
08.01.2006 22:29:25
Peter
Hallo Gregor,
wenn ich Deine Datei (aus anderen Beiträgen) zugrunde lege, kommt bei mir auch nichts, denn die Spalte A ist ja gleich (in Zeile 3) leer nicht aber die Zelle I in der Zeile 2.
So geht dein Makro sofort auf Ende, nämlich auf Wend.
Etwas umgebaut kommt dann was:

Private Sub UserForm_Activate()
Dim zl  As Integer
Dim START_ZEILE  As Integer: START_ZEILE = 2
Dim iCoBO  As Integer
ComboBoxKreditorÄnd.Clear
zl = START_ZEILE
For zl = 2 To Range("A65536").End(xlUp).Row
If Not IsEmpty(Range("A" & zl).Value) Then
If IsEmpty(Cells(zl, 9).Value) Then
ComboBoxKreditorÄnd.AddItem
ComboBoxKreditorÄnd.List(iCoBO, 0) = Cells(zl, "B").Value
ComboBoxKreditorÄnd.List(iCoBO, 1) = Cells(zl, "A").Value
iCoBO = iCoBO + 1
End If
End If
Next zl
End Sub

Viele Grüße Peter
Eine kurze Nachricht, ob es läuft, wäre nett - danke.
Anzeige
AW: Bedingung für ComboBox Inhalt
08.01.2006 22:51:21
GregorJ
Hallo Peter,
das Formular bezieht sich auf eine andere Tabell die nicht sichtbar wird,
"Daten" da ist die Spalte A lückenlos gefüllt, wenn du die Musterdatei aus diesem Beitrag nimmst, und da einmal den Button Eingabe betätigst und wieder schließt, dann wird die Tabelle Daten sichtbar, alternativ kannst du auch die ZelleA1 anwählen und dort nochmal einen . eingeben.
Doch das Problem ist der "mannfred" :-) 41 und 1
Gregor
AW: Bedingung für ComboBox Inhalt
08.01.2006 23:43:45
GregorJ
Hallo Peter,
ich weis nicht ob du so spät noch online bist,
aber ich habe noch etwas ausprobiert,
es klappt wenn die Zahlen in Tabelle "Daten" in Spalte A
mit 100 beginnen, also wenn "mannfred" 101 und 141,
dann geht es super, aber ich werde die Nummern so nicht übernehmen können.
Noch was, gibt es eine Möglichkeit, die Ansicht in ComboBox, unabhängig von der Quelle
Alphabetisch Sortiert zu bekommen?
Gregor
Anzeige
AW: Bedingung für ComboBox Inhalt
08.01.2006 22:38:39
GregorJ
Sorry ich habe mich vertan,
sicher
Private Sub UserForm_Activate()
ich hatte es erst unter
Private Sub UserForm_Initialize()
eingefügt, das ging nicht, da das
Sheets("Daten").Select nicht war,
ja, kein Select im VB aber ohne komme ich noch nicht zurecht.
also kommt Initialize vor Activate, aber wann genau wird Initialize
doch das Problem mit mannfred besteht noch,
wenn mannfred die Nr 1 in Spalte A hat, wenn der ne 3 bekommt, gehts.
:
Gregor
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.
Anzeige
AW: Bedingung für ComboBox Inhalt
09.01.2006 15:06:45
Peter
Hallo Gregor,
hier findest du eine abgespeckte Version deiner Anwendung, um das Eingabemodul zu testen.
So stelle ich mir das Private Sub UserForm_Activate() vor.
Ein Initialize gibt es nicht mehr, man braucht es nicht.
https://www.herber.de/bbs/user/29851.xls
Viele Grüße Peter
Eine kurze Nachricht, ob es läuft, wäre nett - danke.
Danke, das ist absolut super nett
09.01.2006 22:53:42
GregorJ
Danke Peter,
das ist wirklich super nett von dir,
es geht mit beiden Lösungen,
ich habe die letzte in mein Formular eingebaut,
jetzt suche ich nur noch nach einer Möglichkeit,
wie ich die ComboBoxKreditorAlle erst leer angezeigt bekomme,
die ComboBoxKreditorÄnd soll so bleiben, den ersten Datensatz anzeigen,
DankeDankeDanke
Gregor
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige