Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
780to784
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
780to784
780to784
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

listindex problem bei combobox

listindex problem bei combobox
17.07.2006 18:24:03
selo
Hallo an alle
habe da mal wieder ein problem mit dem ich mich an euch wende.
Undzwar wird in eine combobox ein tabellenbereich aus spalte A eingelesen dessen min und max werte in B2 und B3 stehen.
Nun liegt das problem das ich wenn ich in der combobox einen Wert auswähle der dazugehörige wert in Spalte I nicht in der textbox steht.
wie kann ich das problem lösen?
danke im vorraus für alle die mir helfen
https://www.herber.de/bbs/user/35148.xls
gruß
selo

12
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: listindex problem bei combobox
17.07.2006 19:00:23
ChrisL
Hallo
Die ComboBox hat jetzt 9 Spalten, aber nur Spalte A ist sichtbar. Hat den Vorteil, dass du den gesuchten Wert aus der letzten ComboBox Spalte I entnehmen kannst, anstelle von einer "Suche".
Die Zellen B2 und B3 sind nicht "plausibilisiert" d.h. führt zu einem Fehler, wenn falsche Daten eingegeben werden. Evtl. über eine Gültigkeitsprüfung nachholen ;-)
Gruss
Chris

Private Sub ComboBox1_Change()
TextBox1 = ComboBox1.List(ComboBox1.ListIndex, 8)
ComboBox1 = Format(ComboBox1.Value, "dd.mm.yyyy")
End Sub


Private Sub UserForm_Activate()
With Me.ComboBox1
.ColumnCount = 9 '´Spaltenanzahl der Combobox einstellen
.ColumnWidths = "3cm;0cm;0cm;0cm;0cm;0cm;0cm;0cm;0cm" '´Spaltenbreiten einstellen
End With
With ThisWorkbook.Sheets(1)
Me.ComboBox1.RowSource = .Name & "!" & .Range(.Cells(Application.Match(.Range("B2"), .Columns(1)), 1), .Cells(Application.Match(.Range("B3"), .Columns(1)), 9)).Address(0, 0)
End With
End Sub

Anzeige
AW: listindex problem bei combobox
17.07.2006 19:33:08
selo
hallo chris
danke dir ersteinmal.
eine frage wäre da
wieso wird bei TextBox1 = ComboBox1.List(ComboBox1.ListIndex, 8)
der wert aus spalte 9 genommen trotz das hier 8 steht?
ich hatte mir versucht das auf diesem wege zu lösen

Private Sub ComboBox1_Change()
Dim wert As Long, i As Long, ort As String, Lrow As Long
Lrow = Cells(Rows.Count, 1).End(xlUp).Row 'letzte Zelle in Spalte A
wert = Cells(2, 2)
With ActiveSheet
For i = 2 To Lrow
If wert = Cells(i + 1, 1) Then
ort = i + 1
End If
Next i
End With
TextBox1 = Cells(ComboBox1.ListIndex + ort, 9)
End Sub

jedoch scheiterte ich irgendwie an
TextBox1 = Cells(ComboBox1.ListIndex + ort, 9)
wäre das überhaupt möglich gewesen was ich hier versucht hätte?
gruß
selo
Anzeige
AW: listindex problem bei combobox
17.07.2006 20:56:00
ChrisL
Hallo
Ist ganz einfach. ListIndex beginnt im Gegensatz zu Zeilen (Zeile1, Zeile2 usw) bei null (ListIndex 0 = erster Eintrag, ListIndex -1 = kein Eintrag ausgewählt).
Wäre da nicht das Problem betr. Datums-Eingrenzung gewesen, dann wäre die Übersetzung von ListIndex in Zeile wie folgt abgelaufen:
MsgBox Cells(ComboBox1.ListIndex + 1, 9)
Der Ansatz von Christoph ist auch nicht schlecht. Ich vermute die Probleme haben mit dem "Datum" zu tun und könnten auch bei meinem Code auftreten. Dort wo ein Datum steht, steht keins oder ist falsch formatiert (spreche von Zellen M1 und M2). ;-)
N.b. wenn die ComboBox mit 2-Spalten zu definieren ist (im Ursprungs-Code der Fall), ist die AddItem Methode nicht verwendbar. Braucht entweder RowSource oder du definierst ein Array (Datenfeld-Variable).
Gruss
Chris
Anzeige
AW: listindex problem bei combobox
17.07.2006 19:04:47
Jan
Hi,
also bei mir funktioniert es.
mfg Jan
AW: listindex problem bei combobox
17.07.2006 19:05:39
Christoph
Hallo Selo,
mein Vorschlag für den Code der Userform: (s.u.)
Dabei benutze ich die Excel-Funktion "VERGLEICH" (entspricht "Match") um die Zeile der Start- und Endzeit zu bestimmen.
Gruß
Christoph
PS: es heißt "vbModeless" nicht "vbmodless"
PPS: Rückmeldung wäre nett
Option Explicit
Dim lngStartRow As Long
Private Sub ComboBox1_Change()
Me.TextBox1 = ThisWorkbook.Sheets(1).Cells(Me.ComboBox1.ListIndex + lngStartRow, 9)
End Sub
Private Sub UserForm_Activate()
Dim lngEndRow As Long
Dim varVgl As Variant
With ThisWorkbook.Sheets(1)
'Anfangs- und End-Datum bestimmen:
lngStartRow = 0
varVgl = Application.Match(.Cells(2, 2), .Columns(1), 0)
If Not IsError(varVgl) Then lngStartRow = CLng(varVgl)
varVgl = Application.Match(.Cells(3, 2), .Columns(1), 0)
If Not IsError(varVgl) Then lngEndRow = CLng(varVgl)
'Fehlerabfangung:
If lngStartRow = 0 Or lngEndRow = 0 Then
MsgBox "Start- bzw. End-Datum nicht gegeben!"
Exit Sub
End If
If lngEndRow <= lngStartRow Then
MsgBox "End-Datum muss größer Start-Datum sein!"
Exit Sub
End If
'ComboBox füllen:
Me.ComboBox1.Clear
Me.ComboBox1.List = _
.Range(.Cells(lngStartRow, 1), .Cells(lngEndRow, 1)).Value
End With
End Sub

Anzeige
AW: listindex problem bei combobox
17.07.2006 19:54:36
selo
hallo christoph
danke auch dir
jedoch habe ich da ein problem wenn ich anfangs und endwertposition ändere auf zellen (1,13) und (2,13)
und den teil deines codes in With ThisWorkbook.Sheets(1)
'Anfangs- und End-Datum bestimmen:
lngStartRow = 0
varVgl = Application.Match(.Cells(1, 13), .Columns(1), 0)
If Not IsError(varVgl) Then lngStartRow = CLng(varVgl)
varVgl = Application.Match(.Cells(2, 13), .Columns(1), 0)
If Not IsError(varVgl) Then lngEndRow = CLng(varVgl)
springt immer die msgbox "Start- bzw. End-Datum nicht gegeben!" auf.
irgendwie mache ich da etwas falsch jedoch komme ich nicht was
gruß
selo
Anzeige
AW: listindex problem bei combobox
17.07.2006 21:44:27
Christoph
Hallo Selo,
wie Chris schon sagte: der Fehler tritt auf, wenn die Zellen für Start und End-Wert nicht als Datum formatiert sind. Hinzu kommt, das Excel intern auch nicht mit Datumswerten rechnet sondern mit einer Ganzzahl (Anzahl Tage seit 1900).
probier mir das folgende, und gib mir Bescheid
Gruß Christoph
Option Explicit
Dim lngStartRow As Long
Private Sub ComboBox1_Change()
Me.TextBox1 = ThisWorkbook.Sheets(1).Cells(Me.ComboBox1.ListIndex + lngStartRow, 9)
End Sub
Private Sub UserForm_Activate()
Dim lngStartDat As Long, lngEndDat As Long
Dim lngEndRow As Long
Dim varVgl As Variant
With ThisWorkbook.Sheets(1)
'prüfe Anfangs- und End-Wert:
lngStartRow = 0
If Not IsDate(.Cells(1, 13)) Or Not IsDate(.Cells(2, 13)) Then
MsgBox "keine Datumswerte bei Start- bzw. End-Datum gegeben!"
Exit Sub
End If
'Anfangs- und End-Datum bestimmen:
lngStartDat = CLng(CDate(.Cells(1, 13)))
lngEndDat = CLng(CDate(.Cells(2, 13)))
varVgl = Application.Match(lngStartDat, .Columns(1), 0)
If Not IsError(varVgl) Then lngStartRow = CLng(varVgl)
varVgl = Application.Match(lngEndDat, .Columns(1), 0)
If Not IsError(varVgl) Then lngEndRow = CLng(varVgl)
'Fehlerabfangung:
If lngStartRow = 0 Or lngEndRow = 0 Then
MsgBox "Start- bzw. End-Datum nicht gegeben!"
Exit Sub
End If
If lngEndRow <= lngStartRow Then
MsgBox "End-Datum muss größer Start-Datum sein!"
Exit Sub
End If
'ComboBox füllen:
Me.ComboBox1.Clear
Me.ComboBox1.List = _
.Range(.Cells(lngStartRow, 1), .Cells(lngEndRow, 1)).Value
End With
End Sub

Anzeige
AW: listindex problem bei combobox
17.07.2006 22:03:05
selo
hallo christoph
ich habe durch probieren es hierdurch geschafft.
Dim lngEndRow As Long
Dim varVgl As Variant
ActiveWorkbook.Sheets("daten").Select
With Worksheets("daten")
'Anfangs- und End-Datum bestimmen:
lngStartRow = 0
varVgl = Application.Match(.Cells(1, 13), Worksheets("mitarbeiter_cl").Columns(1), 0)
If Not IsError(varVgl) Then lngStartRow = CLng(varVgl)
varVgl = Application.Match(.Cells(2, 13), Worksheets("mitarbeiter_cl").Columns(1), 0)
If Not IsError(varVgl) Then lngEndRow = CLng(varVgl)
'Fehlerabfangung:
If lngStartRow = 0 Or lngEndRow = 0 Then
MsgBox "Start- bzw. End-Datum nicht gegeben!"
Exit Sub
End If
If lngEndRow MsgBox "End-Datum muss größer Start-Datum sein!"
Exit Sub
End If
'ComboBox füllen:
Me.ComboBox1.Clear
Me.ComboBox1.List = _
.Range(.Cells(lngStartRow, 1), .Cells(lngEndRow, 1)).Value
End With
da die beispielmappe nur ein teil eines projektes von mir für die uni ist habe ich nun andere probleme bekommen.
ich hatte folgenden code,welchem noch andere ähneln

Private Sub ComboBox1_Change()
ComboBox1.Value = Format(ComboBox1.Value, "dd.mm.yyyy")
TextBox5.BackColor = vbWhite
Label6.Visible = False
SpinButton1.Value = 0
TextBox1.Value = SpinButton1
TextBox7.Visible = False
Label7.Visible = False
SpinButton1.Value = 0
TextBox5.Value = 0
TextBox6.Value = 0
If Cells(ComboBox1.ListIndex + 2, 10) <> 0 And Cells(ComboBox1.ListIndex + 2, 9) > 0 Then
TextBox4 = Cells(ComboBox1.ListIndex + 2, 10)
TextBox7.Visible = True
TextBox4.BackColor = vbRed
TextBox7 = Cells(ComboBox1.ListIndex + 2, 9) - Cells(ComboBox1.ListIndex + 2, 10)
Label7.Visible = True
Else
If Cells(ComboBox1.ListIndex + 2, 11) >= 1 Then
TextBox4 = Cells(ComboBox1.ListIndex + 2, 11)
TextBox4.BackColor = vbRed
Label6.Visible = True
Label7.Visible = False
TextBox7.Visible = False
Else
If Cells(ComboBox1.ListIndex + 2, 9) > 0 Then
TextBox4 = Cells(ComboBox1.ListIndex + 2, 9)
Else
TextBox4 = 0
TextBox4.BackColor = vbWhite
Label6.Visible = False
End If
TextBox5.BackColor = vbWhite
End If
End If
End Sub

wenn ich z.Bden bereich
If Cells(ComboBox1.ListIndex + 2, 10) 0 And Cells(ComboBox1.ListIndex + 2, 9) > 0 Then
durch
If Cells(Me.ComboBox1.ListIndex + lngStartRow, 10) 0 And Cells(Me.ComboBox1.ListIndex + lngStartRow, 9) > 0 Then
ersetze und natrürlich auch die anderen funktioniert nichts mehr.
gibt es einen einfachen weg dies zu machen sonst muß ich von null anfangen alle makros zu schreiben die in der userform enthalten sind.
Anzeige
AW: listindex problem bei combobox
17.07.2006 22:19:27
Christoph
Hallo,
so beim ersten Überfliegen seh ich da kein Problem, es sei denn!:
Hast du in der obersten Zeile im Code der Userform auch das
Dim lngStartRow As Long
stehn? Das ist wichtig. Denn diese Deklaration gilt für das gesamte Modul. Anderfalls ist lngStartRow=0 und es knallt, weil es keine Zeile 0 gibt.
Wenn das so ist, dann schreib auch gleich "Option Explicit" darüber. Das zwingt dich dazu, Variablen zu deklarieren und spart dir unendlich viel Arbeit bei der Fehlersuche.
Gruß
Christoph
AW: listindex problem bei combobox
17.07.2006 22:34:05
selo
hallo Christoph
ich habe alles gemacht
bekomme jedoch bei
If Cells(Me.ComboBox1.ListIndex + lngstartRow, 10) &lt&gt 0 And Cells(Me.ComboBox1.ListIndex + lngstartRow, 9) &gt 0 Then
einen fehler 1004
anwendungs- oder objektdefinierter fehler
eine kleine frage was bedeutet dieses lngstartRow ich bin noch nicht dahintergestiegen, vielleicht kann ich das auf anderem wege lösen.
gruß
selo
Anzeige
AW: listindex problem bei combobox
18.07.2006 07:24:03
Christoph
Hallo Selo,
lngStartRow ist eine Variable (hab ich so genannt). Beim Start der Userform wird mit
varVgl = Application.Match(lngStartDat, .Columns(1), 0)
die Zeile in Spalte 1 gesucht, in der das Start-Datum steht. Der Variablen lngStartRow wird die Zeilennr dieser "Startzeile" übergeben. Genauso lngEndRow für die Zeile des End-Datums.
Ein weitere Vermutung bzgl. deines Fehlers: Du musst sauber referenzieren. Grade, wenn du mit verschiedenen Tabellenblättern arbeitest. Also nicht:
If Cells(Me.ComboBox1.ListIndex + lngstartRow, 10)  0 ...
sondern:
If Worksheets("Daten").Cells(Me.ComboBox1.ListIndex + lngstartRow, 10)  0 ...
also bei jedem "Range" und "Cells" die Tabelle mit angeben. Gruß Christoph PS: bin wahrscheinlich erst heute abend wieder online
Anzeige
AW: listindex problem bei combobox
18.07.2006 22:40:49
selo
hallo Christoph
ich habe es mit deiner hilfe und herumexperimentieren hinbekommen.
Habe einige lösungsvorschläge zusammengewürfelt und es hinbekommen
ich danke dir recht herzlichst
gruß
selo

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige