AW: Eigenschaften von Textfeldern
27.09.2004 19:20:56
Textfeldern
Hallo Astis,
das ist umfangreich. Ich bin nun nicht der Favchmann für Steuerelemente in der Tabllle. Aber folgender Code müßte auch gehen.
Private Sub TextBox8_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
' Ansatz VB 6 Buch von Peter Monadjemi
' nur Zahlen, ein Komma und nur 2 Stellen nach Komma
Select Case KeyAscii
Case Asc("0") To Asc("9")
If InStr(TextBox8, ",") <> 0 Then
If Len(TextBox8) - InStr(TextBox8, ",") > 1 Then KeyAscii = 0
End If
Case Asc("."), Asc(",")
If InStr(TextBox8, ",") <> 0 Then
KeyAscii = 0
Else
KeyAscii = Asc(",")
End If
Case Asc(vbBack)
' Eingabe von minus
Case Asc("-")
' If Len(Textbox8) = 0 Then
' If InStr(Textbox8, "-") <> 0 Then
' Else
' KeyAscii = Asc("-")
' End If
' Else
' KeyAscii = 0
' End If
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Textbox8_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(TextBox8, "-") >= 1 And Left(TextBox8, 1) <> "-" Then
TextBox8 = Replace(TextBox8, "-", "")
BoWert = True
ElseIf InStr(TextBox8, "-") = 1 And InStr(2, TextBox8, "-") >= 1 Then
BoWert = True
If Left(TextBox8, 1) = "-" Then
TextBox8 = "-" + Replace(TextBox8, "-", "")
Else
TextBox8 = Replace(TextBox8, "-", "")
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 SP2 und Excel Version 2003 SP1.