AW: ListBox
29.07.2003 17:39:50
ChrisL
Hi Silvio
Konkrete Fragen werden im Forum gerne beantwortet, aber fertige Lösungen kannst du hier nicht erwarten. Trotzdem mal ein bischen Code...
Sub Schaltfläche1_BeiKlick()
Load UserForm1
UserForm1.Show
End Sub
Option Explicit
Private Sub CommandButton1_Click()
Unload UserForm1
End Sub
Private Sub CommandButton2_Click()
Dim iZeile As Long
If IsNumeric(TextBox1) = False Or TextBox1 = "" Then
MsgBox "Textbox1 fehlerhaft"
Exit Sub
End If
For iZeile = 3 To Range("A65536").End(xlUp).Row
If Cells(iZeile, 1) = ListBox1 And Cells(iZeile, 2) = ListBox2 Then Exit For
Next iZeile
Cells(iZeile, 3) = TextBox1
Unload UserForm1
End Sub
Private Sub ListBox1_Click()
Dim iZeile As Long
With ListBox2
.Enabled = True
.Clear
For iZeile = 3 To Range("A65536").End(xlUp).Row
If Cells(iZeile, 1) = ListBox1 Then .AddItem Cells(iZeile, 2)
Next iZeile
End With
End Sub
Private Sub ListBox2_Click()
Dim iZeile As Long
TextBox1.Enabled = True
For iZeile = 3 To Range("A65536").End(xlUp).Row
If Cells(iZeile, 1) = ListBox1 And Cells(iZeile, 2) = ListBox2 Then
TextBox1 = Cells(iZeile, 3)
Exit For
End If
Next iZeile
End Sub
Private Sub UserForm_Initialize()
Dim iZeile As Long, iEintrag As Long, Vorhanden As Boolean
For iZeile = 3 To Range("A65536").End(xlUp).Row
Vorhanden = False
For iEintrag = 1 To ListBox1.ListCount
If Cells(iZeile, 1) = ListBox1.List(iEintrag - 1) Then
Vorhanden = True
Exit For
End If
Next iEintrag
If Vorhanden = False Then ListBox1.AddItem Cells(iZeile, 1)
Next iZeile
ListBox2.Enabled = False
TextBox1.Enabled = False
End Sub
Gruss
Chris