Objekt erforderlich
10.02.2021 13:31:50
Christian
Ebenfalls ist der Bereich, der in " " markiert ist noch optimierungbedürftig. Es soll folgendes passieren: Über Kontrollkästchen werden Hobbies ausgewählt und diese werden anschließend in eine Excel-Datei geschrieben - Klappt wunderbar. Jetzt will ich das Formular aber so gestalten, dass nur max. 3 Hobbies ausgewählt werden dürfen und habe dazu absolut keinen Lösungsansatz, ich bitte auch hier um Hilfe.
Sub CommandButton_Register_Click()
Dim OptionButton As MSForms.Control
Dim CheckBox As MSForms.Control
Dim Last As Integer
Dim Benutzer As String
Dim Target As Range
Benutzer = TextBox_Username.Value
Last = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
For Each OptionButton In Frame_Title.Controls
If OptionButton.Value = True Then
ActiveSheet.Cells(Last, 1).Value = OptionButton.Caption
End If
Next OptionButton
" If CheckBox_Boxing.Value = True Then
ActiveSheet.Cells(Last, 9).Value = CheckBox_Boxing.Caption
End If
If CheckBox_Swimming.Value = True Then
ActiveSheet.Cells(Last, 10).Value = CheckBox_Swimming.Caption
End If
If CheckBox_Gardening.Value = True Then
ActiveSheet.Cells(Last, 11).Value = CheckBox_Gardening.Caption
End If
If CheckBox_Running.Value = True Then
ActiveSheet.Cells(Last, 12).Value = CheckBox_Running.Caption
End If
If CheckBox_Cooking.Value = True Then
ActiveSheet.Cells(Last, 13).Value = CheckBox_Cooking.Caption
End If
If CheckBox_Reading.Value = True Then
ActiveSheet.Cells(Last, 14).Value = CheckBox_Reading.Caption
End If "
ActiveSheet.Cells(Last, 2).Value = UserForm_Formular.TextBox_Firstname
ActiveSheet.Cells(Last, 3).Value = UserForm_Formular.TextBox_Surename
ActiveSheet.Cells(Last, 4).Value = UserForm_Formular.TextBox_Street
ActiveSheet.Cells(Last, 5).Value = UserForm_Formular.TextBox_CityCode
ActiveSheet.Cells(Last, 6).Value = UserForm_Formular.TextBox_City
ActiveSheet.Cells(Last, 7).Value = UserForm_Formular.TextBox_Mail
ActiveSheet.Cells(Last, 8).Value = UserForm_Formular.TextBox_Username
Set Benutzer = Worksheet("Tabelle2").Range("H:H").Find(Benutzer, LookIn:=xlValues, _
_
LookAt:=xlWhole)
If Not Benutzer Is Nothing Then
MsgBox "Dieser Nutzername ist bereits vergeben."
End If
End Sub
Danke allen Voraus.
Grüße
Christian