Datum ohne Punkt eingeben
15.04.2007 15:37:41
Uwe Hladik
Hallo an Alle und einen schönen Sonntag,
habe hier im Forum mal folgenden Code gefunden und in meiner Userform eingesetzt um die lästige Punkteingabe im Datum zu vermeiden.
Option Explicit
Dim BoEnter As Boolean
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
' erstellt von Hajo.ziplies@web.de Stand 01.08.03
' Datumseingabe 01.01.03;1.1.03 oder komlettes Jahr
' Eingabe des Tages und des Monat zweistellig werden die Punkte automatisch gesetzt
' sie können nur gelöscht durch markierung des punktes und der Zahl davor
' Buchstaben werden ausgeschlossen, nur Zahlen und Punkt
' die Überprüfung ob Datum erfolgt in
Private Sub TextBox1_AfterUpdate()
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc(".")
If Len(TextBox1) = 0 Then
KeyAscii = 0
Else
If Len(TextBox1) - Len(Application.Substitute(TextBox1, ".", "")) = 2 Then
KeyAscii = 0
ElseIf Len(TextBox1) > 1 Then
If Mid(TextBox1, Len(TextBox1), 1) = "." Then KeyAscii = 0
Else
KeyAscii = Asc(".")
End If
End If
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub TextBox1_Change()
If BoEnter = True Then Exit Sub
If Len(TextBox1) = 2 Then
If InStr(TextBox1, ".") = 0 And BoEnter = False Then TextBox1 = TextBox1 & "."
ElseIf Len(TextBox1) = 5 Then
If Len(TextBox1) - Len(Application.Substitute(TextBox1, ".", "")) < 2 Then
TextBox1 = TextBox1 & "."
End If
End If
End Sub
Private Sub TextBox1_AfterUpdate()
BoEnter = True
If Right(TextBox1, 1) = "." Then TextBox1 = Mid(TextBox1, 1, Len(TextBox1) - 1)
' Jahreszahl vom aktuellen Jahr ergänzen falls nicht vorhanden
If Len(TextBox1) - Len(Application.Substitute(TextBox1, ".", "")) = 1 Then
TextBox1 = TextBox1 & "." & Year(Date)
End If
If IsDate(TextBox1.Text) Then
If Format(CDate(TextBox1.Value), "dd.mm.yy") <> TextBox1 Then
MsgBox "Das Datum wurde übersetzt"
End If
TextBox1 = Format(CDate(TextBox1.Value), "dd.mm.yy")
Else
TextBox1 = ""
End If
BoEnter = False
End Sub
...nur macht er mir bei der übertragung auf meine Liste einen Fehler.....
Private Sub CommandButton1_Click() <-------wird gelb dargestellt.
z = Range("A1").End(xlDown).Row + 1 <------ hier unterlegt er das z und sagt "Variable nicht _
definiert"
If z > 65000 Then z = 2
Cells(z, 1) = ComboBox1
Cells(z, 2) = TextBox1
Cells(z, 3) = TextBox2
Cells(z, 4) = TextBox3
Cells(z, 5) = ComboBox2
Cells(z, 6) = CDbl(TextBox4)
Cells(z, 7) = CDbl(TextBox5)
Cells(z, 8) = CDbl(TextBox6)
Cells(z, 9) = CDbl(TextBox7)
Cells(z, 10) = ComboBox3
Cells(z, 11) = TextBox8
Cells(z, 12) = TextBox9
Cells(z, 13) = TextBox10
UserForm1.Hide
End Sub
... kann mir da einer sagen was geändert werden muß!
Vorab schon mal vielen Dank!
Gruß Uwe