Live-Forum - Die aktuellen Beiträge
Datum
Titel
24.04.2024 19:29:30
24.04.2024 18:49:56
Anzeige
Archiv - Navigation
700to704
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
700to704
700to704
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Textbox aus Combobox füllen

Textbox aus Combobox füllen
01.12.2005 11:02:30
Gisela
Hallo,
Kann mir bitte jemand weiterhelfen.
Warum füllt sich die Textbox3 erst bei der zweiten Auswahl?
Bei der ersten Auswahl bleibt die TB3 leer, danach funktionierts.

Private Sub ComboBox1_Change()
Sheets("Tabelle1").Activate
Dim lngZeile As Long
lngZeile = ComboBox1.ListIndex + 3
If lngZeile > 0 Then
TextBox2.Value = Cells(lngZeile, 1).Value
TextBox3.Value = Cells(lngZeile, 4).Value
End If
If ComboBox1.MatchFound = True Then
ComboBox2.ListIndex = ComboBox1.ListIndex
End If
End Sub


Private Sub ComboBox2_Change()
Sheets("Tabelle1").Activate
Dim lngZeile As Long
lngZeile = ComboBox2.ListIndex + 3
If lngZeile > 0 Then
TextBox2.Value = Cells(lngZeile, 1).Value
TextBox3.Value = Cells(lngZeile, 4).Value
End If
If ComboBox2.MatchFound = True Then
ComboBox1.ListIndex = ComboBox2.ListIndex
End If
End Sub

Vielen Dank und Grüße
Gisela

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Textbox aus Combobox füllen
01.12.2005 11:41:17
Daniel
Hallo Gisela,
manchmal gibt es Probleme mit der Activate Methode. Versuch mal die Zellen direkt abzufragen so:


      
Private Sub ComboBox1_Change()
    
Dim lngZeile As Long
    lngZeile = ComboBox1.ListIndex + 3
    
If lngZeile > 0 Then
        TextBox2.Value = Worksheets(
"Tabelle1").Cells(lngZeile, 1).Value
        TextBox3.Value = Worksheets(
"Tabelle1").Cells(lngZeile, 4).Value
        
End If
    
If ComboBox1.MatchFound = True Then
        ComboBox2.ListIndex = ComboBox1.ListIndex
    
End If
End Sub
Private Sub ComboBox2_Change()
    
Dim lngZeile As Long
    lngZeile = ComboBox2.ListIndex + 3
    
If lngZeile > 0 Then
        TextBox2.Value = Worksheets(
"Tabelle1").Cells(lngZeile, 1).Value
        TextBox3.Value = Worksheets(
"Tabelle1").Cells(lngZeile, 4).Value
    
End If
    
If ComboBox2.MatchFound = True Then
        ComboBox1.ListIndex = ComboBox2.ListIndex
    
End If
End Sub
 


P.S. dein Code hat bei mir einwandfrei funktioniert
Gruss
Daniel
Anzeige
AW: Textbox aus Combobox füllen
01.12.2005 13:05:54
Gisela
Hallo Daniel,
vielen Dank für Deine Hilfe.
Ich hab wohl woanders ein Problem. Ich hatte bei beiden TB ControlSource angegeben.
Hab das jetzt mal rausgenommen und mir folgendes "zusammengebaut".
Das ist bestimmt nicht illegant, funktioniert aber erst mal. Hast Du oder vielleicht jemand anderer eine bessere Lösung?

Private Sub ComboBox1_Change()
Sheets("Tabelle1").Activate
Dim lngZeile As Long
lngZeile = ComboBox1.ListIndex + 3
If lngZeile > 0 Then
TextBox2.Value = Cells(lngZeile, 1).Value
TextBox3.Value = Cells(lngZeile, 4).Value
Sheets("Tabelle2").Select
Range("B11").Value = TextBox1.Text
Range("F11").Value = TextBox3.Text
End If
If ComboBox1.MatchFound = True Then
ComboBox2.ListIndex = ComboBox1.ListIndex
End If
End Sub


Private Sub ComboBox2_Change()
Sheets("Tabelle1").Activate
Dim lngZeile As Long
lngZeile = ComboBox2.ListIndex + 3
If lngZeile > 0 Then
TextBox2.Value = Cells(lngZeile, 1).Value
TextBox3.Value = Cells(lngZeile, 4).Value
Sheets("Tabelle2").Select
Range("B11").Value = TextBox1.Text
Range("F11").Value = TextBox3.Text
End If
If ComboBox2.MatchFound = True Then
ComboBox1.ListIndex = ComboBox2.ListIndex
End If
End Sub

Vielen Dank für jede Hilfe
Grüße
Gisela
Anzeige
AW: Textbox aus Combobox füllen
01.12.2005 13:14:25
Gisela
Hallo,
da war noch ein Fehler drin. So siehts bei mir jetzt aus.
Kann man das besser darstellen?

Private Sub ComboBox1_Change()
Sheets("Tabelle1").Activate
Dim lngZeile As Long
lngZeile = ComboBox1.ListIndex + 3
If lngZeile > 0 Then
TextBox2.Value = Cells(lngZeile, 1).Value
TextBox3.Value = Cells(lngZeile, 4).Value
Sheets("Tabelle2").Select
Range("B11").Value = TextBox2.Text
Range("F11").Value = TextBox3.Text
End If
If ComboBox1.MatchFound = True Then
ComboBox2.ListIndex = ComboBox1.ListIndex
End If
End Sub


Private Sub ComboBox2_Change()
Sheets("Tabelle1").Activate
Dim lngZeile As Long
lngZeile = ComboBox2.ListIndex + 3
If lngZeile > 0 Then
TextBox2.Value = Cells(lngZeile, 1).Value
TextBox3.Value = Cells(lngZeile, 4).Value
Sheets("Tabelle2").Select
Range("B11").Value = TextBox2.Text
Range("F11").Value = TextBox3.Text
End If
If ComboBox2.MatchFound = True Then
ComboBox1.ListIndex = ComboBox2.ListIndex
End If
End Sub

Anzeige
AW: Textbox aus Combobox füllen
01.12.2005 13:27:42
Dani
Hallo Gisela,
ich habe nur drei kleine Anmerkungen welche sich vor allem auszahlen wenn der Code grösser wird:
- Deklarationen immer zuerst in den Prozeduren vornehmen
- Offsets (wie die drei bei dir) als Konstanten ablegen wenn später in der Tabelle etwas ändert musst du nur diese Konstante ändern und nicht suchen wo sie überall im Code benutzt wird.
- Activate / Select sollten nicht verwendet werden da dies meistens auch nicht nötig ist
Ich bin selber nur Anfänger möchte aber diese Tipps (welche ich auch erhalten habe weitergeben)
Der Code auf diese Weise bereinigt sieht so aus:


      
Option Explicit
Const Zeilenoffset = 3
Private Sub ComboBox1_Change()
Dim lngZeile As Long
lngZeile = ComboBox1.ListIndex + Zeilenoffset
With Worksheets("Tabelle1")
    .TextBox2.Value = Cells(lngZeile, 1).Value
    .TextBox3.Value = Cells(lngZeile, 4).Value
End With
With Workscheets("Tabelle2")
    .Range(
"B11").Value = TextBox1.Text
    .Range(
"F11").Value = TextBox3.Text
End With
If ComboBox1.MatchFound = True Then
ComboBox2.ListIndex = ComboBox1.ListIndex
End Sub
 


Gruss
Daniel
Anzeige
AW: Textbox aus Combobox füllen
01.12.2005 14:09:23
Gisela
Hallo Daniel,
vielen Dank für den Tipp. Werds mal ausprobieren.
Grüße
Gisela

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige