'Función que devuelve si ya ha metido una coma en el text
Private Function mfbYaHayUnaComa() As Boolean
mfbYaHayUnaComa = IIf(InStr(1, Text1.Text, ",") = 0, False, True)
End Function
'Evento que controla todo lo que se mete en el texto
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "." Then KeyAscii = Asc(",")
If KeyAscii <> vbKeyBack Then
If Len(Text1.Text) > 0 Then
If KeyAscii <> Asc(",") Then
If Not IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0
Beep
End If
ElseIf mfbYaHayUnaComa Then
KeyAscii = 0
Beep
End If
Else
If Not IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0
Beep
End If
End If
End If
End Sub
'Cuando pierdo el foco formateo el número introducido
Private Sub Text1_LostFocus()
Text1.Text = Format(Text1.Text, "#,###,###,###,###,##0.00")
End Sub