Gruppe
Dialog
Problem
Die Liste aus Spalte A soll ohne Doppelte in eine UserForm-ComboBox eingelesen werden. Nach Auswahl eines Namens soll in einem Label die zu diesem Namen gehörige Summe aus Spalte B übernommen werden.
ClassModule: frmSumme
Private Sub cboNamen_Change()
lblSumme.Caption = _
Format(WorksheetFunction _
.SumIf(Columns(1), cboNamen.Value, Columns(2)), "#,##0")
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim col As New Collection
Dim iRow As Integer
iRow = 1
On Error Resume Next
Do Until IsEmpty(Cells(iRow, 1))
col.Add Cells(iRow, 1), Cells(iRow, 1)
If Err = 0 Then
cboNamen.AddItem Cells(iRow, 1)
Else
Err.Clear
End If
iRow = iRow + 1
Loop
On Error GoTo 0
cboNamen.ListIndex = 0
End Sub
StandardModule: Modul1
Sub CallForm()
frmSumme.Show
End Sub