Código para Seleccionar Celda. En Userform
Estoy en una Tarea de programacion y nos asignaron crear un formulario.
La realize en Base a Pokemon, El formulario ingresas el nombre, Numero y Sus Tipos.
Tengo todo bien, Pero como ultimo punto nos asignaron "Crear un boton que haga Busqueda"
Quiere decir, Que busque en la base de datos Creada e Identifique los Datos que seleccione.
Use Un Codigo que realiza la busqueda, Sin Embargo no encuentro Como "Seleccionar"
Aunque Sea En el MSG que genera, Me gustaria dijera Por Ejemplo
"Datos Encontrados "Nombre: Pikachu, Tipo: Electrico, Segundo tipo: (si no tiene, Muestra en blanco), Numero: 25 "
Y En la base de datos que se Crea, Marque La Celda como si la seleccionaras (solamente)
Este es el Codigo:
Si Gustan Coloco Tambien el Formulario de Excell para ver.
Repito, Usamos Userform del visualbasic
Private Sub CommandButton1_Click()
Selection.EntireRow.Insert
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
TextBox1.SetFocus
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub CommandButton3_Click()
If TextBox1 = "value.1" Then
MsgBox "Capturar datos"
TextBox1.SetFocus
Exit Sub
End If
If TextBox2 = "value.2" Then
MsgBox "Capturar datos"
TextBox2.SetFocus
Exit Sub
End If
If TextBox3 = "value.3" Then
MsgBox "Capturar datos"
TextBox3.SetFocus
Exit Sub
End If
If TextBox4 = "value.4" Then
MsgBox "Capturar datos"
TextBox4.SetFocus
Exit Sub
End If
encontrado = False
If IsNumeric(TextBox1) Then
valt1 = Val(TextBox1.Value)
Else
valt1 = TextBox1
End If
If IsNumeric(TextBox2) Then
valt2 = Val(TextBox2.Value)
Else
valt2 = TextBox2
End If
If IsNumeric(TextBox3) Then
valt3 = Val(TextBox.Value)
Else
valt3 = TextBox3
End If
If IsNumeric(TextBox4) Then
valt4 = Val(TextBox4.Value)
Else
valt4 = TextBox4
End If
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
If Cells(i, "A") = valt1 And _
Cells(i, "B") = valt2 Then
TextBox3 = Cells(i, "C")
TextBox4 = Cells(i, "D")
encontrado = True
Exit For
End If
Next
If encontrado = True Then
MsgBox "Datos Encontrados"
End If
If encontrado = False Then
MsgBox "Datos no encontrados"
End If
End Sub
Private Sub TextBox1_Change()
Range("A2").Select
ActiveCell.FormulaR1C1 = TextBox1
End Sub
Private Sub TextBox2_Change()
Range("B2").Select
ActiveCell.FormulaR1C1 = TextBox2
End Sub
Private Sub TextBox3_Change()
Range("C2").Select
ActiveCell.FormulaR1C1 = TextBox3
End Sub
Private Sub TextBox4_Change()
Range("D2").Select
ActiveCell.FormulaR1C1 = TextBox4
End Sub
Private Sub TextBox5_Change()
TextBox5.Value = ActiveSheet.Range("B242").Value
End Sub
Private Sub UserForm_Click()
End Sub