Si el Textbox contiene números que tome Valor si contiene texto que lo ingrese como texto

Hola necesito su ayuda, tengo esta macro que me ayudo el experto aprendemos,

Necesito que al ingresar un valor en el textbox detecte si es solo números o números y texto, si es solo números que el application.match sea números, y si es numero y texto que sea considerado como texto, ojala se entienda, aquí adjunto el código:

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If ListBox1.Value = "" Or IsNull(ListBox1.Value) Then
MsgBox "Seleccione un destino en la lista", vbCritical, "INVENTARIO"
Exit Sub
End If
If TextBox2 = "" Then
MsgBox "Capture un IMEI", vbCritical, "INVENTARIO"
Exit Sub
End If

lin = Application.Match(Val(TextBox2), Columns("B"), 0)

If Not IsError(lin) Then

Cells(lin, "A") = Date

Cells(lin, "G") = Val(TextBox1)

Cells(lin, "F") = ListBox1

TextBox2 = ""

TextBox2.SetFocus

Cancel = True

Call traspasar

Else

MsgBox "IMEI no encontrado", vbCritical, "INVENTARIO"

End If

End Sub

1 Respuesta

Respuesta
1

Prueba con la siguiente macro

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If ListBox1.Value = "" Or IsNull(ListBox1.Value) Then
MsgBox "Seleccione un destino en la lista", vbCritical, "INVENTARIO"
Exit Sub
End If
If TextBox2 = "" Then
MsgBox "Capture un IMEI", vbCritical, "INVENTARIO"
Exit Sub
End If
If IsNumeric(TextBox2) Then
buscado = Val(TextBox2)
Else
buscado = TextBox2
End If
lin = Application.Match(buscado, Columns("B"), 0)
If Not IsError(lin) Then
Cells(lin, "A") = Date
Cells(lin, "G") = Val(TextBox1)
Cells(lin, "F") = ListBox1
TextBox2 = ""
TextBox2.SetFocus
Cancel = True
Call traspasar
Else
MsgBox "IMEI no encontrado", vbCritical, "INVENTARIO"
End If
End Sub

Saludos.Dam
Si es lo que necesitas.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas