RE:URGENTE- TextBox formato de Celda Número
Private Sub Form_Load()
' comprueba el formato numérico del sistema
sDecimal = Format(0.1, "#.#")
sDecimal = IIf(InStr(sDecimal, ","), ",", ".")
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim sCar As String * 1
sCar = Chr(KeyAscii)
If KeyAscii = 13 Then
' si se ha pulsado ENTER pasamos el foco al siguiente control
KeyAscii = 0
SendKeys "{TAB}"
Exit Sub
End If
If sCar = "." Or sCar = "," Then
' comprueba si se ha pulsado coma o punto y lo convierte al
' formato del sistema
KeyAscii = IIf(sDecimal = ",", 44, 46)
sCar = Chr(KeyAscii)
' si ya se ha puesto un punto decimal, no admite otro
If (InStr(Text1, sCar) > 0) Then
KeyAscii = 0
Exit Sub
End If
ElseIf InStr("0123456789-.,$" & Chr(8), sCar) = 0 Then
' sólo admite números, signo negativo, punto, coma y retroceso
' Nota: Si no queremos negativos, quitar el signo menos de la cadena
KeyAscii = 0
Exit Sub
' comprueba que el signo menos esté sólo al principio
' Nota: Si no queremos negativos, quitar esta condición
ElseIf sCar = "-" Then
If InStr(2, "-", Text1) = 0 Then
KeyAscii = 0
End If
End If
End Sub