Mittels folgendem Code versuche ich Daten in ein Tabellenblatt schreiben zu lassen!
Private Sub CommandButton2_Click()
If ComboBox1 = "1. Kredit" Then
Dim Dia As UserForm
Dim lng As Long
Dim Treffer As Range
Dim i As Integer
Set Treffer = Krediterfassung.Columns(1).Find(What:=CDate(TextBox5), LookAt:=xlWhole)
If Treffer Is Nothing Then
lng = Range("A65536").End(xlUp).Offset(1, 0).Row
Else
i = MsgBox("Dieser Satz wurde bereits erfasst! Überschreiben?", vbYesNo + vbQuestion)
If i = 6 Then
lng = Treffer.Row
Else
Exit Sub
End If
End If
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(1), 0), 2) = ComboBox2.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(1), 0), 3) = TextBox6.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(1), 0), 4) = TextBox7.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(1), 0), 5) = TextBox15.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(1), 0), 6) = TextBox19.Text
Sheets("Krediterfassung").Range("E5") = CDate(TextBox5)
If TextBox20 = "" Then
Exit Sub
Else
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(1), 0), 7) = CDbl(TextBox20)
End If
End If
If ComboBox1 = "2. Kredit" Then
Set Treffer = Krediterfassung.Columns(10).Find(What:=CDate(TextBox5), LookAt:=xlWhole)
If Treffer Is Nothing Then
lng = Range("A65536").End(xlUp).Offset(1, 0).Row
Else
i = MsgBox("Dieser Satz wurde bereits erfasst! Überschreiben?", vbYesNo + vbQuestion)
If i = 6 Then
lng = Treffer.Row
Else
Exit Sub
End If
End If
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(10), 0), 11) = ComboBox2.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(10), 0), 12) = TextBox6.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(10), 0), 13) = TextBox7.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(10), 0), 14) = TextBox15.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(10), 0), 15) = TextBox19.Text
Sheets("Krediterfassung").Range("N5") = CDate(TextBox5)
If TextBox20 = "" Then
Exit Sub
Else
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(10), 0), 16) = CDbl(TextBox20)
End If
End If
If ComboBox1 = "3. Kredit" Then
Set Treffer = Krediterfassung.Columns(19).Find(What:=CDate(TextBox5), LookAt:=xlWhole)
If Treffer Is Nothing Then
lng = Range("A65536").End(xlUp).Offset(1, 0).Row
Else
i = MsgBox("Dieser Satz wurde bereits erfasst! Überschreiben?", vbYesNo + vbQuestion)
If i = 6 Then
lng = Treffer.Row
Else
Exit Sub
End If
End If
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(19), 0), 20) = ComboBox2.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(19), 0), 21) = TextBox6.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(19), 0), 22) = TextBox7.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(19), 0), 23) = TextBox15.Text
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(19), 0), 24) = TextBox19.Text
Sheets("Krediterfassung").Range("W5") = CDate(TextBox5)
If TextBox20 = "" Then
Exit Sub
Else
Cells(Application.Match(CDbl(CDate(TextBox5.Value)), Columns(19), 0), 25) = CDbl(TextBox20)
End If
End If
End Sub
Wenn ich in der ComboBox1 "1. Kredit" wähle funzt der Übertrag in die Tabelle, aber bei den anderen beiden kommt die Fehlermeldung Laufzeitfehler 13 - Typen unverträglich.Wie muss ich meinen Code abändern damit es funzt, denn wenn ich Teil 2 so abändere, dass das Datum in Spalte A gesucht wird läuft es ja auch, aber nicht wenn er in Spalte J oder S suchen soll?
Ich hoffe ihr könnt mich verstehen und mir eine Lösung anbieten. Vielen Dank im Vorraus!!!
Herzlichst Frank H.!!!