Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1524to1528
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Automatische Kommasetzung

Automatische Kommasetzung
14.11.2016 08:36:48
Floeh
Hallo,
ich hoffe Ihr könnt mir weiterhelfen. Ich habe folgend einen "BMI-Rechner", hier muss in der TextBox2 die Größe (m,cm) eingetragen werden. Ich habe bereits eine MsgBox bei ungültiger Eingabe, besser wäre die Automatische Kommasetzung einzufügen. Wie mache ich dies?

Option Explicit
Private Sub CommandButton1_Click()
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox3.BackColor = &HFFFFFF
OptionButton1 = True
TextBox1.SetFocus
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bChange = True Then
bChange = False
Exit Sub
End If
If Trim(TextBox1.Value) = "" Then
MsgBox "Bitte geben Sie Ihr Gewicht in Kilogramm ein.", _
48, "   Hinweis für " & Application.UserName
Cancel = True
TextBox1.SetFocus
End If
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim BMI  As Single
If Trim(TextBox2.Value) = "" Then
MsgBox "Bitte geben Sie Ihre Körpergröße in Meter und Zentimeter ein.", _
48, "   Hinweis für " & Application.UserName
Cancel = True
TextBox2.SetFocus
ElseIf InStr(TextBox2.Value, ",") = 0 Then
MsgBox "Bitte geben Sie Ihre Körpergröße in Meter einem Komma und Zentimeter ein.", _
48, "   Hinweis für " & Application.UserName
Cancel = True
TextBox2.SetFocus
Else
BMI = CSng(CDbl(TextBox1.Value) / CDbl(TextBox2.Value) ^ 2)
If OptionButton1 Then
Select Case BMI
Case Is  40
TextBox3.BackColor = &HC0&
Label4.Caption = "massive Adipositas"
End Select
Else
Select Case BMI
Case Is  40
TextBox3.BackColor = &HC0&
Label4.Caption = "massive Adipositas"
End Select
End If
TextBox3.Value = Format(BMI, "0.0")
TextBox1.SetFocus
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("1234567890.," & Chr$(8), Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
End If
If KeyAscii = Asc(".") Then
KeyAscii = Asc(",")
End If
'     nur ein Dezimalzeichen zulassen
If InStr(1, TextBox1.Text, ",", 0) And KeyAscii = Asc(",") Then
KeyAscii = 0
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("1234567890.," & Chr$(8), Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
End If
If KeyAscii = Asc(".") Then
KeyAscii = Asc(",")
End If
'     nur ein Dezimalzeichen zulassen
If InStr(1, TextBox2.Text, ",", 0) And KeyAscii = Asc(",") Then
KeyAscii = 0
End If
End Sub
Private Sub UserForm_Initialize()
OptionButton1 = True
End Sub

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Automatische Kommasetzung
14.11.2016 09:09:49
Daniel
Hi
lass dir doch die Größe gleich in cm in die TextBox eingeben, dann brauchst du kein Komma.
Gruß Daniel
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige