Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Notice: Undefined offset: 1 in /home/www/s013w173/html/mambots/system/blocklist.php on line 38 Warning: Cannot modify header information - headers already sent by (output started at /home/www/s013w173/html/mambots/system/blocklist.php:38) in /home/www/s013w173/html/includes/joomla.php on line 715 Warning: Cannot modify header information - headers already sent by (output started at /home/www/s013w173/html/mambots/system/blocklist.php:38) in /home/www/s013w173/html/index.php on line 251 Warning: Cannot modify header information - headers already sent by (output started at /home/www/s013w173/html/mambots/system/blocklist.php:38) in /home/www/s013w173/html/index.php on line 252 Warning: Cannot modify header information - headers already sent by (output started at /home/www/s013w173/html/mambots/system/blocklist.php:38) in /home/www/s013w173/html/index.php on line 253 Warning: Cannot modify header information - headers already sent by (output started at /home/www/s013w173/html/mambots/system/blocklist.php:38) in /home/www/s013w173/html/index.php on line 254 Warning: Cannot modify header information - headers already sent by (output started at /home/www/s013w173/html/mambots/system/blocklist.php:38) in /home/www/s013w173/html/index.php on line 255 Excel InLife - STEUERELEMENT - Kombinationsfeld

Willkommen auf Excel-Inlife

Diese Seite soll Ihnen im Umgang mit Excel im Alltag helfen. Hierbei finden Sie im Downloadbereich Beispieldateien und Add-Ins, mit denen Sie ihre alltäglichen Excel-Probleme lösen können. Zudem finden Sie im "Tipps&Tricks"-Bereich Lösungen zu Fragen, die in verschiedenen Foren öfters auftreten. 

 
  Home arrow Tutorials arrow Steuerelemente arrow STEUERELEMENT - Kombinationsfeld
Notice: Undefined variable: caption in /home/www/s013w173/html/mambots/content/multithumb.php on line 182 Notice: Undefined variable: caption in /home/www/s013w173/html/mambots/content/multithumb.php on line 182 Notice: Undefined variable: caption in /home/www/s013w173/html/mambots/content/multithumb.php on line 182 Notice: Undefined variable: caption in /home/www/s013w173/html/mambots/content/multithumb.php on line 182 Notice: Undefined variable: caption in /home/www/s013w173/html/mambots/content/multithumb.php on line 182 Notice: Undefined variable: caption in /home/www/s013w173/html/mambots/content/multithumb.php on line 182
STEUERELEMENT - Kombinationsfeld
(35 Stimmen)
Dieses Tutorial soll Ihnen einen Einblick in die Programmierung von Kombinationsfeldern in Userforms geben. Dabei wird zunächst auf die verschiedenen möglichen Parameter eingegangen. Im Anschluss soll das Füllen, das Verarbeiten und das Löschen der Werte aus dem Steuerelemente aufgezeigt werden.

Kombinationsfelder sind eine schöne Variante, dem Benutzer die Möglichkeit zu geben, aus vordefinierten Werten auswählen zu können. Jedoch ist es vorallem für Anfänger in der VBA-Programmierung nicht leicht, mit diesen Elementen umzugehen.

1. Einstellungsparameter

Das Steuerelemente Kombinationsfeld (Combobox) bringen eine Vielzahl von Einstellungen mit, die entweder Direkt über das Eigenschaftsfenster gesetzt, oder über VBA angesprochen werden können. (Möglicherweise sind nicht alle Parameter in allen Excel-Versionen vorhanden). Die nachfolgenden Übersichten sollen die verschiedenen Parameter mit den möglichen Ausprägungen darstellen.

rs2


























rs3


















rs4





rs6

rs5































2. Füllen

Daten können in verschiedener Weise an das Steuerelement übergeben werden. Hierbei kann zwischen der Row-Source-Methode, der Additem-Methode und der List-Methode unterschieden werden.

Die Anwendung der verschiedenen Varianten soll mit Hilfe des folgenden Beispiel exemplarisch veranschaulicht werden. Selbstverständlich muss berücksichtigt werden, dass es sich hier lediglich um einfache, rudimentäre Beispiele handelt, die jedoch in der Praxis abgewandelt werden können und den eigenen Bedürfnissen angepasst werden müssen. Dabei sollen das Ziel dieses Tutorials sein, beide Spalten in ein Kombinationsfeld anzuzeigen.

  A B
1 Name Vorname
2 Sebastian Schulz
3 Stefan Muster
4 Kathrin Schneider
Tabelle 1: Beispieldaten

Die Row-Source-Methode stellt die einfachste Variante der Datenübernahme im Kombinationsfeldern dar. Hierbei kann die Übergabe auf der einen Seite im Eigenschaftsfenster (RowSource) direkt (Siehe Abbildung 1) oder in der Übergabe der Row-Source-Methode durch VBA (siehe Code 1) erfolgen. Da wir in unserem Beispiel von einer zwei-Spaltigen Tabelle ausgehen, muss hier noch zusätzlich darauf geachtet werden, dass auch die Eigenschaft "ColumnCount" den Wert 2 zugewiesen bekommt. Bei dem Fehlen dieses Wertes geht Excel von einer einspaltigen Tabelle aus, unabhängig von der Eigenschaft, die im RowSource mitgegeben wurde.

rs1

Private Sub UserForm_Initialize()
     ComboBox1.RowSource = "A2:B4"
     ComboBox1.ColumnCount = 2
End Sub

Code 1: RowSource-VBA-Befehl

Die zweite Möglichkeit Werte in ein Kombinationsfeld zu schreiben stellt die List-Methode dar. Diese ähnelt sehr der Row-Source Methode. Der Unterschied besteht jedoch darin, dass dieser nicht im Eigenschaftsfenster des Steuerelements angesprochen werden und nur über VBA zugewiesen werden kann.

Private Sub UserForm_Initialize()
    ComboBox1.List = Sheets("Tabelle1").Range("A2:A4").Value
End Sub

Code 2: List-Methode-VBA-Befehl

Die Additem-Methode geht hier von einem anderen Ansatz aus, die Daten zu übergeben. Sie eignet sich besonder für die Übergabe von Werten aus einem diskontinuierlichen Bereiches, wie beispielsweise die Übernahme jediglich jeder zweiten Zeile oder Werten oder Werten, die einer bestimmt Bedingung unterliegen.

Zusätzlich können statische Einträge in das Kombinationsfeld geschrieben werden, die sich nicht auf einen Tabellenbereich beziehen. (siehe Code 2)

Private Sub UserForm_Initialize()
    With ComboBox1
        .AddItem "Sebastian"
        .AddItem "Stefan"
        .AddItem "Kathrin"
    End With
End Sub

Code 3: AddItem-VBA-Befehl (Allgemein)

Um auf unsere obere Tabelle zurück zukommen, müssen die Einträge mit Hilfe einer Schleife in das Kombinationsfeld geschrieben werden. Die erste Spalte aus unserer Beispielstabelle wird mit dem Code 3 übergeben.

Private Sub UserForm_Initialize()
    Dim i
    With ComboBox1
        For i = 2 To 4
            .AddItem Cells(i, 1).Value
        Next i
    End With
End Sub

Code 4: AddItem-VBA-Befehl (Einspaltig)

Für die Werte der zweiten Spalte müssen wir uns der List-Methode bedienen.

Private Sub UserForm_Initialize()
    Dim i
    With ComboBox1
        .ColumnCount = 2
        For i = 2 To 4
            .AddItem Cells(i, 1).Value
            .List(.ListCount - 1, 1) = Cells(i, 2).Value
        Next i
    End With
End Sub

Code 5: AddItem-VBA-Befehl (Zweispaltig)

3. Verarbeiten

In Bearbeitung

4. Löschen

Natürlich können Daten, die mit Hilfe der AddItem-Methode übernommen worden sind aus dem Kombinationsfeld wieder gelöscht werden. Der Nachfolgende Code veranschaulicht, wie der Name "Sebastian Schulz" aus dem Kombinationsfeld entfernt werden kann.

ComboBox1.RemoveItem 0

Code 6: Remove (statisch)

Es muss jedoch berücksichtigt werden, dass die Indexierung bei 0, anstatt bei 1 beginnt. Manchmal ist es jedoch erforderlich, dass nicht ein zuvor festgelegter Wert gelöscht wird, sondern der zu löschende Wert vom User bestimmt werden kann. Das nachfolgende Beispiel veranschaulicht, wie der selektierte Eintrag aus dem Kombinationsfeld gelöscht wird. Hierzu ist es notwendig, den ListIndex zu ermitteln.

ComboBox1.RemoveItem (ComboBox1.ListIndex)

Code 7: Remove (variabel)

Um den Inhalt eines gesamten Kombinationsfeld zu löschen, kann folgender Code verwendet werden.

ComboBox1.clear

Code 8: Remove (komplett)

 
< zurück