AW: Format
09.09.2009 16:02:54
JogyB
Hi.
Versuch es mal so:
' Erzeugt die Anzeige mit
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
' Wenn nicht numerisch, dann gehts nicht weiter
If Not IsNumeric(TextBox1.Value) And TextBox1.Value "" Then
Cancel = True
ElseIf TextBox1.Value "" Then
Application.EnableEvents = False
TextBox1.Value = Format(TextBox1.Value, "#0.00") & " "
Application.EnableEvents = False
End If
End Sub
' Verhindert die Doppeleingabe von Kommas
Private Sub TextBox1_Change()
Static lastValue As String
Dim cursPos As Long
If InStr(TextBox1.Value, ",") InStrRev(TextBox1.Value, ",") Then
' bei zweitem Komma wird die alte Eingabe wiederhergestellt
' die Cursor-Position wird bei Eingabe von Einzelzeichen ebenfalls
' korrekt wiederhergestellt, bei Copy&Paste von mehreren Zeichen nicht
cursPos = TextBox1.SelStart
TextBox1.Value = lastValue
TextBox1.SelStart = Application.Max(cursPos - 1, 0)
Else
lastValue = TextBox1.Value
End If
End Sub
' Löscht das -Zeichen bei der Eingabe
Private Sub TextBox1_Enter()
' Wenn was drinsteht, dann ist auch das Eurozeichen drin
If TextBox1.Value "" Then
Application.EnableEvents = False
TextBox1.Value = Left(TextBox1.Value, Len(TextBox1.Value) - 2)
Application.EnableEvents = True
End If
End Sub
' Läßt nur Zahlen und das Komma als Eingabe zu
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii 57) And KeyAscii 44 Then
KeyAscii = 0
End If
End Sub
Den Namen der Textbox mußt Du ggf. anpassen.
Gruss, Jogy