AW: Möchte auch negative Zahlen zulassen
27.03.2004 18:39:59
Hajo_Zi
Hallo Lenny
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
' Ansatz VB 6 Buch von Peter Monadjemi
' nur Zahlen und ein Komma
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc("."), Asc(",")
If InStr(TextBox1, ",") <> 0 Then
KeyAscii = 0
Else
KeyAscii = Asc(",")
End If
Case Asc(vbBack)
' Eingabe von minus
Case Asc("-")
' If Len(TextBox1) = 0 Then
' If InStr(TextBox1, "-") <> 0 Then
' Else
' KeyAscii = Asc("-")
' End If
' Else
' KeyAscii = 0
' End If
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Textbox1_Change()
' Eingabe von Minus auch nachträglich
' diese Code ist eine gemeinasme Arbeit von Hajo und
' theonlyrobi (Robert) aus dem Forum <a href="http://www.ms-office-forum.net/forum/forumdisplay.php?s=&forumid=29">http://www.ms-office-forum.net/forum/forumdisplay.php?s=&forumid=29</a>
Dim BoWert As Boolean
If InStr(TextBox1, "-") >= 1 And Left(TextBox1, 1) <> "-" Then
TextBox1 = Replace(TextBox1, "-", "")
BoWert = True
ElseIf InStr(TextBox1, "-") = 1 And InStr(2, TextBox1, "-") >= 1 Then
BoWert = True
If Left(TextBox1, 1) = "-" Then
TextBox1 = "-" + Replace(TextBox1, "-", "")
Else
TextBox1 = Replace(TextBox1, "-", "")
End If
End If
If BoWert = True Then MsgBox "Ein Minus darf nur an erster Stelle stehen! Beispiel: -123,45"
End Sub
Bitte keine Mail, Probleme sollten im Forum gelöst werden.
Microsoft MVP für Excel
Das Forum lebt auch von den Rückmeldungen.
Betriebssystem XP Pro und Excel Version XP Pro SP 3