Gruppe
Dialog
Problem
In einer UserForm-ListBox dürfen nur Datensätze gleichen Datums ausgewählt werden.
ClassModule: frmMultiSelect
Dim bln As Boolean
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub lstValues_Change()
Dim iRow As Integer, iCount As Integer
Dim sTxt As String
If bln Then
bln = False
Exit Sub
End If
sTxt = lstValues.List(lstValues.ListIndex, 0)
For iRow = 0 To lstValues.ListCount - 1
If lstValues.Selected(iRow) Then
iCount = iCount + 1
If iCount = 2 Then Exit For
End If
Next iRow
If iCount > 1 Then
For iRow = 0 To lstValues.ListCount - 1
If iRow <> lstValues.ListIndex Then
If lstValues.Selected(iRow) And CStr(lstValues.List(iRow, 0)) <> sTxt Then
MsgBox "Es dürfen nur Datensätze eines Datums ausgewählt werden!"
bln = True
lstValues.Selected(lstValues.ListIndex) = False
Exit For
End If
End If
Next iRow
End If
End Sub
Private Sub UserForm_Initialize()
lstValues.List = Range("A1").CurrentRegion.Value
End Sub
StandardModule: Modul1
Sub CallForm()
frmMultiSelect.Show
End Sub