ich bin bisher nur stiller Mitleser gewesen und habe nun selbst ein Problem:
Ich habe eine Userform im visual basic gebaut, in die zuerst ein paar Angaben eingetragen oder auch ausgewählt werden. Bei Klick auf den Sende-Button (CommandButton1), sollen dann alle Einträge überprüft werden und wenn alles korrekt ist, der Inhalt in eine Excel-Tabelle geschrieben werden.
In der Userform gibt es eine Checkbox, die je nach Auswahl in der Combobox1 mit einem Label überdeckt wird oder eben sichtbar ist. Wenn die Checkbox überdeckt ist, soll automatisch in Spalte 13 der Excel-Tabelle "kostenlos" stehen, sonst bei Anwählen der Checkbox = 1 oder bei leerer Checkbox = 2.
Das Überdecken bei den vorher festgelegten kostenlosen Dingen funktioniert prima.
Aber das Eintragen in die Excel-Datei funktioniert nicht.
Meine Codes sehen so aus:
Private Sub ComboBox1_Change()
If ComboBox1.Value = "def" Then
UserForm2.Show
UserForm1.Label10.Visible = False
End If
If ComboBox1.Value = "ghi" Then
UserForm3.Show
End If
If ComboBox1.Value = "abc" Then
UserForm1.Label11.Visible = True
Else: UserForm1.Label11.Visible = False
End If
If ComboBox1.Value = "ghi" Or ComboBox1.Value = "abc" Or ComboBox1.Value = "jkl" Or
ComboBox1.Value = "mno" Or ComboBox1.Value = "pqr" Or ComboBox1.Value = "stu" Or
ComboBox1.Value = "vwx" Or ComboBox1.Value = "yza" Or ComboBox1.Value = "bcd" Then
UserForm1.Label10.Visible = True
End If
If ComboBox1.Value = "aaa" Or ComboBox1.Value = "bbb" Or ComboBox1.Value = "ccc" Or
ComboBox1.Value = "ddd" Or ComboBox1.Value = "eee" Or ComboBox1.Value = "fff" Or
ComboBox1.Value = "ggg" Then
UserForm1.Label10.Visible = False
End If
End Sub
.
.
.
Private Sub CommandButton1_Click()
If Not IsNumeric(Me.TextBox1.Value) Then
Call MsgBox("Bitte Nr. eingeben!", vbExclamation Or vbOKOnly)
Me.TextBox1.SetFocus
Else: TextBox3.Text = Evaluate("=VLOOKUP(" & TextBox1.Text & ",'Tabelle2'!A:B,2,0)")
End If
If Not IsDate(Me.TextBox9.Value) Then
Call MsgBox("Bitte Datum eingeben! (Format: TT.MM.JJJJ)", vbExclamation Or vbOKOnly)
Me.TextBox9.SetFocus
If IsDate(Me.TextBox9.Text) Then
If Not Me.TextBox9.Text = Format(CDate(Me.TextBox9.Text), "DD/MM/YYYY") Then
MsgBox "Falsches Datumsformat!"
Me.TextBox9.SetFocus
End If
End If
End If
If IsNumeric(Me.TextBox1.Value) And IsDate(Me.TextBox9.Value) And ComboBox1.Value "abc" _
_
Then
Dim a As Long
a = Cells(Rows.Count, 3).End(xlUp).Row + 1
Cells(a, 15) = Me.TextBox9.Value
Cells(a, 1) = Me.TextBox1.Value
Cells(a, 2) = Me.ComboBox1.Value
Cells(a, 3) = Me.TextBox3.Value
Cells(a, 4) = Me.TextBox4.Value
Cells(a, 5) = Me.TextBox6.Value
Cells(a, 8) = Me.Txt_Datum1.Value
End If
If IsNumeric(Me.TextBox1.Value) And IsDate(Me.TextBox9.Value) And ComboBox1.Value = "abc" _
_
Then
a = Cells(Rows.Count, 3).End(xlUp).Row + 1
Cells(a, 16) = Me.TextBox9.Value
Cells(a, 1) = Me.TextBox1.Value
Cells(a, 2) = Me.ComboBox1.Value
Cells(a, 3) = Me.TextBox3.Value
Cells(a, 4) = Me.TextBox4.Value
Cells(a, 5) = Me.TextBox6.Value
Cells(a, 8) = Me.Txt_Datum1.Value
If ComboBox2.Value = "getrennt (nur bei abc)" Then
Cells(a, 10) = "getrennt"
ElseIf ComboBox2.Value = "zusammengefasst (nur bei abc)" Then
Cells(a, 10) = "zusammengefasst"
Else: Cells(a, 10) = Me.ComboBox2.Text
If Label10.Visible = True Then
Cells(a, 13) = "kostenlos"
If Label10.Visible = False Then
If CheckBox1.Value = True Then
Cells(a, 13) = "1"
ElseIf CheckBox1.Value = False Then
Cells(a, 13) = "2"
End If
End If
End If
End If
CheckBox1.Value = False
End If
End Sub