Insertar numeros con letras en una celda y detectar error con un msgbox

Me acaba de ayudar bastante en la anterior macro (EL cual me ha servido de mucha ayuda), me ha salido un problemita no en el código si no a la hora de utilizarlo ya que por error no te mencione lo sig..

Este es el código tuyo que me funciona excelente:

Calle: 117 x 50 (este no me acepta) es correcto

Lo que me paso es que aquí por mi ciudad se usa así algunas veces

Calle: 117 diag x 50 A

Calle: 117 A x 50 diag

No se si se pueda se permita poner "diag" en cualquiera y cualquier letra del abecedario

Siempre respetando el código tuyo...

Calle: 115a X 58 diag (correcto) respeto limites

Calle 117a X 64 diag ( incorrecto) no respeto limites

1 Respuesta

Respuesta
1

Y si en lugar de poner todo en una celda (habiendo tantas en excel), capturas en 4 celdas:

           A             B             C          D                         E

1     Calle        Letras      Calle      Letras              Concatenar

2      117         Diag           50           a                  117Diag X 50a     

2      115         Cda            48           b                  115Cda X 48b

2      113          c                44          Cjon              113c X 44Cjon  

2      111                           40                                111 X 40 

Etc

Lo que te estoy poniendo son ejemplos, todas las capturas las haces siempre sobre las mismas 4 celdas, si quieres puedes poner el resultado en una quinta celda con la "X", de esta forma podrías validar celda por celda, sin tener que estar validando letras y números, en la celda B2, puedes permitir letras "diag", "cda", "cjon", etc, mientras que en las celdas A2 y C2 que acepte solamente números.

Ya envíe un ejemplo a tu correo

Te anexo el código del formulario

Private Sub CommandButton1_Click()
'Por.Dante Amor
    If OptionButton1 Then
        If TextBox1 = "" Then
            MsgBox "Captura la calle 1", vbExclamation, "DOMICILIO"
            TextBox1.SetFocus
            Exit Sub
        End If
        If TextBox3 = "" Then
            MsgBox "Captura el numero", vbExclamation, "DOMICILIO"
            TextBox3.SetFocus
            Exit Sub
        End If
    End If
    '
    If Application.IsEven(Val(TextBox1)) Then
        If Val(TextBox1) > 60 Then
            MsgBox "Error en la calle 1, es superior a los números pares", vbExclamation, "DOMICILIO"
            TextBox1.SetFocus
            Exit Sub
        End If
    Else
        If Val(TextBox1) > 115 Then
            MsgBox "Error en la calle 1, es superior a los números impares", vbExclamation, "DOMICILIO"
            TextBox1.SetFocus
            Exit Sub
        End If
    End If
    '
    If OptionButton2 Then
        If TextBox4 = "" Then
            MsgBox "Captura la calle 2", vbExclamation, "DOMICILIO"
            TextBox4.SetFocus
            Exit Sub
        End If
        '
        If Application.IsEven(Val(TextBox4)) Then
            If Val(TextBox4) > 60 Then
                MsgBox "Error en la calle 2, es superior a los números pares", vbExclamation, "DOMICILIO"
                TextBox4.SetFocus
                Exit Sub
            End If
        Else
            If Val(TextBox4) > 115 Then
                MsgBox "Error en la calle 2, es superior a los números impares", vbExclamation, "DOMICILIO"
                TextBox4.SetFocus
                Exit Sub
            End If
        End If
    End If
    '
    Sheets("NUEVO CLIENTE").[D9] = TextBox1 & " " & TextBox2 & " " & TextBox3 & " " & ComboBox1
    Sheets("NUEVO CLIENTE").[D10] = TextBox4 & " " & TextBox5 & " " & TextBox6
    '
    MsgBox "Domicilio creado", vbInformation, "DOMICILIO"
    unloada Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub OptionButton2_Click()
'Por.Dante Amor
    If TextBox1 = "" Then
        MsgBox "Captura la calle 1"
        TextBox1.SetFocus
    End If
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Por.Dante Amor
    If Not (KeyAscii >= 48 And KeyAscii <= 57) Then
        KeyAscii = 0
    End If
End Sub
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Por.Dante Amor
    If Not (KeyAscii >= 65 And KeyAscii <= 90) Then
        KeyAscii = 0
    End If
End Sub
Private Sub TextBo3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Por.Dante Amor
    If Not (KeyAscii >= 48 And KeyAscii <= 57) Then
        KeyAscii = 0
    End If
End Sub
Private Sub TextBox4_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Por.Dante Amor
    If Not (KeyAscii >= 48 And KeyAscii <= 57) Then
        KeyAscii = 0
    End If
End Sub
Private Sub TextBox5_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Por.Dante Amor
    If Not (KeyAscii >= 65 And KeyAscii <= 90) Then
        KeyAscii = 0
    End If
End Sub
Private Sub TextBo6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Por.Dante Amor
    If Not (KeyAscii >= 48 And KeyAscii <= 57) Then
        KeyAscii = 0
    End If
End Sub
Private Sub UserForm_Activate()
    OptionButton1 = True
    ComboBox1.AddItem "Diag"
End Sub

solo una duda:

esto que significa? es nuevo para mi

 If Not (KeyAscii >= 48 And KeyAscii <= 57) Then        KeyAscii = 0    End If

Es para validar que sólo acepte los códigos ascii del 48 al 57, son los números del 0 al 9, cualquier otra letra o carácter que pongas no será aceptado

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas