Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1472to1476
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
Inhaltsverzeichnis

ComboBox Tabellenwahl

ComboBox Tabellenwahl
05.02.2016 12:40:04
Floeh
moin,
kann mit jemand helfen? ... Wie kann ich eine Tabelle in der ComboBox auswählen?
ComboBox1 soll auf Tabelle 1 zugreifen, ComboBox2 auf Tabelle 2, usw.
Danke schon Mal im Vorraus!

Private Sub ComboBox1_Change()
If ComboBox1.ListIndex > -1 Then
TextBox1 = Cells(ComboBox1.ListIndex + 1, 3)
TextBox2 = Cells(ComboBox1.ListIndex + 1, 5)
TextBox3 = Cells(ComboBox1.ListIndex + 1, 10)
TextBox4 = Cells(ComboBox1.ListIndex + 1, 12)
TextBox5 = Cells(ComboBox1.ListIndex + 1, 13)
Else
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
End If
End Sub
Private Sub UserForm_Activate()
Dim Zeilenanzahl As Integer
Dim Start As Integer
Dim i As Integer
Dim wb As Workbook
Dim ws1 As Worksheet
Set wb = ActiveWorkbook
Set ws1 = wb.ActiveSheet
Start = 1
Zeilenanzahl = ws1.Cells(Rows.Count, 1).End(xlUp).Row
For i = Start To Zeilenanzahl
UserForm1.ComboBox1.AddItem ws1.Cells(i, 2).Value
Next i
End Sub

6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: ComboBox Tabellenwahl
06.02.2016 07:25:30
Crazy
Moinmoin
erklär mal genauer was du vor hast
MfG Tom

AW: ComboBox Tabellenwahl
06.02.2016 07:34:48
Floeh
Hallo Tom,
ich habe in meinem 'VBA-Tool' Multiseiten angelegt, welche jeweils eine ComboBox hat und mehrere TextBoxen füllen sollen:
ComboBox1 befindet sich auf Page1 und soll Daten aus der Tabelle1 holen.
ComboBox2 befindet sich auf Page2 und soll Daten aus der Tabelle2 holen.
usw.
Gruss
Floeh

AW: ComboBox Tabellenwahl
06.02.2016 08:05:49
Crazy
Hallo
das könnte dann so aussehen
Private Sub ComboBox1_Change()
Dim i As Integer
With Sheets("Tabelle1")
If ComboBox1.ListIndex > -1 Then
TextBox1 = .Cells(ComboBox1.ListIndex + 1, 3)
TextBox2 = .Cells(ComboBox1.ListIndex + 1, 5)
TextBox3 = .Cells(ComboBox1.ListIndex + 1, 10)
TextBox4 = .Cells(ComboBox1.ListIndex + 1, 12)
TextBox5 = .Cells(ComboBox1.ListIndex + 1, 13)
Else
For i = 1 To 5
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub ComboBox2_Change()
Dim i As Integer
With Sheets("Tabelle2")
If ComboBox1.ListIndex > -1 Then
TextBox6 = .Cells(ComboBox2.ListIndex + 1, 3)
TextBox7 = .Cells(ComboBox2.ListIndex + 1, 5)
TextBox8 = .Cells(ComboBox2.ListIndex + 1, 10)
TextBox9 = .Cells(ComboBox2.ListIndex + 1, 12)
TextBox10 = .Cells(ComboBox2.ListIndex + 1, 13)
Else
For i = 6 To 10
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub ComboBox3_Change()
Dim i As Integer
With Sheets("Tabelle3")
If ComboBox1.ListIndex > -1 Then
TextBox11 = .Cells(ComboBox3.ListIndex + 1, 3)
TextBox12 = .Cells(ComboBox3.ListIndex + 1, 5)
TextBox13 = .Cells(ComboBox3.ListIndex + 1, 10)
TextBox14 = .Cells(ComboBox3.ListIndex + 1, 12)
TextBox15 = .Cells(ComboBox3.ListIndex + 1, 13)
Else
For i = 11 To 15
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub UserForm_Activate()
Dim varDaten1 As Variant
Dim varDaten2 As Variant
Dim varDaten3 As Variant
varDaten1 = Sheets("Tabelle1").Range("B1:B" & Sheets("Tabelle1").Cells(Rows.Count, 2).End( _
xlUp).Row)
varDaten2 = Sheets("Tabelle2").Range("B1:B" & Sheets("Tabelle2").Cells(Rows.Count, 2).End( _
xlUp).Row)
varDaten3 = Sheets("Tabelle3").Range("B1:B" & Sheets("Tabelle3").Cells(Rows.Count, 2).End( _
xlUp).Row)
With ComboBox1
.List = varDaten1
End With
With ComboBox2
.List = varDaten2
End With
With ComboBox3
.List = varDaten3
End With
End Sub

möglich, dass es auch mit Klassenprogrammierung geht, aber da hab ich keinen Plan von
MfG Tom

Anzeige
AW: ComboBox Tabellenwahl
06.02.2016 10:51:48
Floeh
Super funktioniert soweit ganz gut. Danke!
Jetzt ist es nur so: Wenn ich einen Eintrag aus ComboBox2 auswähle, bleiben die Textfelder leer. Es füllt sich allerdings, wenn ich in ComboBox1 einen Eintrag ausgewählt habe.
Private Sub ComboBox1_Change()
Dim i As Integer
With Sheets("Tabelle1")
If ComboBox1.ListIndex > -1 Then
TextBox1 = .Cells(ComboBox1.ListIndex + 1, 5)
TextBox2 = .Cells(ComboBox1.ListIndex + 1, 10)
TextBox3 = .Cells(ComboBox1.ListIndex + 1, 3)
TextBox4 = .Cells(ComboBox1.ListIndex + 1, 12)
TextBox5 = .Cells(ComboBox1.ListIndex + 1, 13)
Else
For i = 1 To 5
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub ComboBox2_Change()
Dim i As Integer
With Sheets("Tabelle2")
If ComboBox1.ListIndex > -1 Then
TextBox6 = .Cells(ComboBox2.ListIndex + 1, 5)
TextBox7 = .Cells(ComboBox2.ListIndex + 1, 10)
TextBox8 = .Cells(ComboBox2.ListIndex + 1, 3)
TextBox9 = .Cells(ComboBox2.ListIndex + 1, 12)
TextBox10 = .Cells(ComboBox2.ListIndex + 1, 13)
Else
For i = 6 To 10
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub ComboBox3_Change()
Dim i As Integer
With Sheets("Tabelle3")
If ComboBox1.ListIndex > -1 Then
TextBox11 = .Cells(ComboBox3.ListIndex + 1, 5)
TextBox12 = .Cells(ComboBox3.ListIndex + 1, 10)
TextBox13 = .Cells(ComboBox3.ListIndex + 1, 3)
TextBox14 = .Cells(ComboBox3.ListIndex + 1, 12)
TextBox15 = .Cells(ComboBox3.ListIndex + 1, 13)
Else
For i = 11 To 15
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub ComboBox4_Change()
Dim i As Integer
With Sheets("Tabelle4")
If ComboBox1.ListIndex > -1 Then
TextBox16 = .Cells(ComboBox4.ListIndex + 1, 5)
TextBox17 = .Cells(ComboBox4.ListIndex + 1, 10)
TextBox18 = .Cells(ComboBox4.ListIndex + 1, 3)
TextBox19 = .Cells(ComboBox4.ListIndex + 1, 12)
TextBox20 = .Cells(ComboBox4.ListIndex + 1, 13)
Else
For i = 16 To 20
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub UserForm_Activate()
Dim varDaten1 As Variant
Dim varDaten2 As Variant
Dim varDaten3 As Variant
Dim varDaten4 As Variant
varDaten1 = Sheets("Tabelle1").Range("B1:B" & Sheets("Tabelle1").Cells(Rows.Count, 2).End(  _
_
xlUp).Row)
varDaten2 = Sheets("Tabelle2").Range("B1:B" & Sheets("Tabelle2").Cells(Rows.Count, 2).End(  _
_
xlUp).Row)
varDaten3 = Sheets("Tabelle3").Range("B1:B" & Sheets("Tabelle3").Cells(Rows.Count, 2).End(  _
_
xlUp).Row)
varDaten4 = Sheets("Tabelle4").Range("B1:B" & Sheets("Tabelle4").Cells(Rows.Count, 2).End(  _
_
xlUp).Row)
With ComboBox1
.List = varDaten1
End With
With ComboBox2
.List = varDaten2
End With
With ComboBox3
.List = varDaten3
End With
With ComboBox4
.List = varDaten4
End With
End Sub

Anzeige
AW: ComboBox Tabellenwahl
06.02.2016 11:35:34
Crazy
Hi
mein Fehler
hier muss noch geändert werden
in Combobox2 & Combobox3
If ComboBox1.ListIndex > -1 Then

in Combobox2_Change
If ComboBox2.ListIndex > -1 Then

und in Combobox3_Change
If ComboBox3.ListIndex > -1 Then

MfG Tom

AW: ComboBox Tabellenwahl
06.02.2016 15:30:03
Floeh
Klasse. Danke!!!
Jetzt brauch ich nur noch einen Speicher-Button je Multiseite. Wie bekomme ich die geänderten Einträge auf die unterschiedliche Tabellenblätter?
Private Sub Speichern_Click()
If CheckBox1 = True Then
Cells(ComboBox1.ListIndex + 1, 5) = TextBox1
Cells(ComboBox1.ListIndex + 1, 10) = TextBox2
Cells(ComboBox1.ListIndex + 1, 3) = TextBox3
Cells(ComboBox1.ListIndex + 1, 12) = TextBox4
Cells(ComboBox1.ListIndex + 1, 13) = TextBox5
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
UserForm_Activate
CheckBox1 = False
ThisWorkbook.Save
Else
MsgBox ("Bitte bestätigen Sie die Änderung mit dem Kontrollkästchen!")
End If
End Sub

Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige