Gruppe
Dialog
Problem
Wie kann ich die Elementliste einer ComboBox um ein Element erweitern?
ClassModule: frmStoffdaten
Private Sub cboStoffdaten_Change()
Dim iRow As Integer
If cboStoffdaten.ListIndex = 0 Then
frmStoff.Show
iRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(iRow, 1) = frmStoff.txtStoff.Text
cboStoffdaten.AddItem frmStoff.txtStoff.Text
Else
If IsEmpty(Cells(1, 2)) Then
iRow = 1
Else
iRow = Cells(Rows.Count, 2).End(xlUp).Row + 1
End If
Cells(iRow, 2) = cboStoffdaten.Value
End If
End Sub
Private Sub cmdOK_Click()
Unload Me
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim iRow As Integer
iRow = 1
With cboStoffdaten
.Clear
.AddItem "Neu"
Do While IsEmpty(Cells(iRow, 1)) = False
.AddItem Cells(iRow, 1)
iRow = iRow + 1
Loop
End With
End Sub
ClassModule: frmStoff
Private Sub cmdInsert_Click()
Dim iRow As Integer
iRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(iRow, 1).Value = txtStoff.Text
frmStoffdaten.cboStoffdaten.AddItem txtStoff.Text
Unload Me
End Sub
StandardModule: basMain
Sub CallForm()
frmStoffdaten.Show
End Sub