Como puedo buscar mediante un textbox en un formulario en bva y traer la mismo la información.

Con la siguiente macro puedo buscar datos y traerlos a mi formulario para modificarlos mediante un ComboBox, lo que necesito es realizar lo mismo pero no con el ComBobox sino con un TextBox donde yo ingrese el dato a buscar. Este es el código que tengo:

1 Respuesta

Respuesta
1

Muestra el código que tiene para modificarlo y sino mira este a ver si te silve

Como buscar un dato en un formulario

No olvide valorar si te silve esta pregunta y la otra

Discúlpame, olvide incluir el código, es el siguiente:

Sub cargarut()
ComboBox2.Clear
Sheets("2016").Activate
Range("A1").Select
For i = 1 To 5000
If ActiveCell.Offset(i, 0).Value <> "" Then
ComboBox2.AddItem ActiveCell.Offset(i, 0).Value
End If
Next
End Sub
Sub carganombre()
ComboBox3.Clear
Sheets("2016").Activate
Range("D1").Select
For i = 1 To 5000
If ActiveCell.Offset(i, 0).Value <> "" Then
ComboBox3.AddItem ActiveCell.Offset(i, 0).Value
End If
Next
End Sub
Private Sub CheckBox1_Click()

ComboBox2.Enabled = True
cargarut

End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
ComboBox3.Enabled = True
CheckBox1.Enabled = False
ComboBox2.Enabled = False
carganombre
Else
ComboBox3.Enabled = False
CheckBox1.Enabled = True
ComboBox3.Clear
End If
End Sub
Private Sub ComboBox2_Change()
Dim var2 As String
If ComboBox2 = "" Then
Else
CommandButton1.Locked = False
Sheets("2016").Activate
If ComboBox2 = Empty Then
MsgBox "Para modificar primero seleccione la Orden de Servicio", vbInformation, "Registro"
ComboBox2.ListIndex = 0
ComboBox2.SetFocus
End If

var2 = ComboBox2.Column(0)
Cells.Find(What:=ComboBox2.Value, After:=ActiveCell, LookIn:=xlFormulas, lookat:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If var2 = ActiveCell.Value Then

TextBox1.Value = ActiveCell.Value
TextBox2 = ActiveCell.Offset(0, 1)
ComboBox1 = ActiveCell.Offset(0, 2)
TextBox4 = ActiveCell.Offset(0, 3)
ComboBox4 = ActiveCell.Offset(0, 4)
ComboBox5 = ActiveCell.Offset(0, 5)
TextBox7 = ActiveCell.Offset(0, 6)
TextBox8 = ActiveCell.Offset(0, 7)
TextBox9 = ActiveCell.Offset(0, 8)
TextBox10 = ActiveCell.Offset(0, 9)
TextBox11 = ActiveCell.Offset(0, 10)
TextBox12 = ActiveCell.Offset(0, 11)
TextBox13 = ActiveCell.Offset(0, 12)
TextBox14 = ActiveCell.Offset(0, 13)
TextBox15 = ActiveCell.Offset(0, 14)
TextBox16 = ActiveCell.Offset(0, 15)
TextBox17 = ActiveCell.Offset(0, 16)
TextBox18 = ActiveCell.Offset(0, 17)
TextBox19 = ActiveCell.Offset(0, 18)
TextBox20 = ActiveCell.Offset(0, 19)
TextBox2.Locked = False
ComboBox1.Locked = False
TextBox4.Locked = False
ComboBox4.Locked = False
ComboBox5.Locked = False
TextBox7.Locked = False
TextBox8.Locked = False
TextBox9.Locked = False
TextBox10.Locked = False
TextBox11.Locked = False
TextBox12.Locked = False
TextBox13.Locked = False
TextBox14.Locked = False
TextBox15.Locked = False
TextBox16.Locked = False
TextBox17.Locked = False
TextBox18.Locked = False
TextBox19.Locked = False
TextBox20.Locked = False

End If
End If
End Sub
Private Sub ComboBox3_Change()
If ComboBox3 = "" Then
Else
CommandButton1.Locked = False
Sheets("2016").Activate
If ComboBox3 = Empty Then
MsgBox "Para modificar primero indique Nº de DAM", vbInformation, "Registro"
ComboBox3.ListIndex = 0
ComboBox3.SetFocus
End If
var3 = ComboBox3.Column(0)
Cells.Find(What:=ComboBox3.Value, After:=ActiveCell, LookIn:=xlFormulas, lookat:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If var3 = ActiveCell Then

TextBox1 = ActiveCell.Offset(0, 0)
TextBox2 = ActiveCell.Offset(0, 1)
ComboBox1 = ActiveCell.Offset(0, 2)
TextBox4 = ActiveCell.Offset(0, 3)
ComboBox4 = ActiveCell.Offset(0, 4)
ComboBox5 = ActiveCell.Offset(0, 5)
TextBox7 = ActiveCell.Offset(0, 6)
TextBox8 = ActiveCell.Offset(0, 7)
TextBox9 = ActiveCell.Offset(0, 8)
TextBox10 = ActiveCell.Offset(0, 9)
TextBox11 = ActiveCell.Offset(0, 10)
TextBox12 = ActiveCell.Offset(0, 11)
TextBox13 = ActiveCell.Offset(0, 12)
TextBox14 = ActiveCell.Offset(0, 13)
TextBox15 = ActiveCell.Offset(0, 14)
TextBox16 = ActiveCell.Offset(0, 15)
TextBox17 = ActiveCell.Offset(0, 16)
TextBox18 = ActiveCell.Offset(0, 17)
TextBox19 = ActiveCell.Offset(0, 18)
TextBox20 = ActiveCell.Offset(0, 19)
TextBox4.Locked = False
TextBox2.Locked = False
ComboBox1.Locked = False
ComboBox4.Locked = False
ComboBox5.Locked = False
TextBox7.Locked = False
TextBox8.Locked = False
TextBox9.Locked = False
TextBox10.Locked = False
TextBox11.Locked = False
TextBox12.Locked = False
TextBox13.Locked = False
TextBox14.Locked = False
TextBox15.Locked = False
TextBox16.Locked = False
TextBox17.Locked = False
TextBox18.Locked = False
TextBox19.Locked = False
TextBox20.Locked = False

End If
End If
End Sub
Private Sub CommandButton1_Click()
Sheets("2016").Activate
If TextBox1 = "" Or TextBox2 = "" Or ComboBox1 = "" Or TextBox19 = "" Then
MsgBox "Está dejando campos requeridos vacios por favor completelos", vbInformation, "Registro"
TextBox1.SetFocus
Else
If CheckBox1.Value = True Then
ActiveCell.Offset(0, 0) = TextBox1.Value

ActiveCell.Offset(0, 0) = TextBox1.Value
ActiveCell.Offset(0, 1) = TextBox2.Value
ActiveCell.Offset(0, 2) = ComboBox1.Value
ActiveCell.Offset(0, 3) = TextBox4.Value
ActiveCell.Offset(0, 4) = ComboBox4.Value
ActiveCell.Offset(0, 5) = ComboBox5.Value
ActiveCell.Offset(0, 6) = TextBox7.Value
ActiveCell.Offset(0, 7) = TextBox8.Value
ActiveCell.Offset(0, 9) = TextBox9.Value
ActiveCell.Offset(0, 9) = TextBox10.Value
ActiveCell.Offset(0, 10) = TextBox11.Value
ActiveCell.Offset(0, 11) = TextBox12.Value
ActiveCell.Offset(0, 12) = TextBox13.Value
ActiveCell.Offset(0, 13) = TextBox14.Value
ActiveCell.Offset(0, 14) = TextBox15.Value
ActiveCell.Offset(0, 15) = TextBox16.Value
ActiveCell.Offset(0, 16) = TextBox17.Value
ActiveCell.Offset(0, 17) = TextBox18.Value
ActiveCell.Offset(0, 18) = TextBox19.Value
ActiveCell.Offset(0, 19) = TextBox20.Value
MsgBox "Datos actualizados correctamente", vbInformation, "Registro"
TextBox1 = ""
TextBox2 = ""
ComboBox1 = ""
TextBox4 = ""
ComboBox4 = ""
ComboBox5 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
TextBox11 = ""
TextBox12 = ""
TextBox13 = ""
TextBox14 = ""
TextBox15 = ""
TextBox16 = ""
TextBox17 = ""
TextBox18 = ""
TextBox19 = ""
TextBox20 = ""
TextBox1.Locked = True
TextBox2.Locked = True
ComboBox1.Locked = True
TextBox4.Locked = True
ComboBox4.Locked = True
ComboBox5.Locked = True
TextBox7.Locked = True
TextBox8.Locked = True
TextBox9.Locked = True
TextBox10.Locked = True
TextBox11.Locked = True
TextBox12.Locked = True
TextBox13.Locked = True
TextBox14.Locked = True
TextBox15.Locked = True
TextBox16.Locked = True
TextBox17.Locked = True
TextBox18.Locked = True
TextBox19.Locked = True
TextBox20.Locked = True
Else
ActiveCell = TextBox1.Value
ActiveCell.Offset(0, 1) = TextBox2.Value
ActiveCell.Offset(0, 2) = ComboBox1.Value
ActiveCell.Offset(0, 3) = TextBox4.Value
ActiveCell.Offset(0, 4) = ComboBox4.Value
ActiveCell.Offset(0, 5) = ComboBox5.Value
ActiveCell.Offset(0, 6) = TextBox7.Value
ActiveCell.Offset(0, 7) = TextBox8.Value
ActiveCell.Offset(0, 8) = TextBox9.Value
ActiveCell.Offset(0, 9) = TextBox10.Value
ActiveCell.Offset(0, 10) = TextBox11.Value
ActiveCell.Offset(0, 11) = TextBox12.Value
ActiveCell.Offset(0, 12) = TextBox13.Value
ActiveCell.Offset(0, 13) = TextBox14.Value
ActiveCell.Offset(0, 14) = TextBox15.Value
ActiveCell.Offset(0, 15) = TextBox16.Value
ActiveCell.Offset(0, 16) = TextBox17.Value
ActiveCell.Offset(0, 17) = TextBox18.Value
ActiveCell.Offset(0, 18) = TextBox19.Value
ActiveCell.Offset(0, 19) = TextBox20.Value

MsgBox "Datos actualizados correctamente", vbInformation, "Registro"
TextBox1 = ""
TextBox2 = ""
ComboBox1 = ""
TextBox4 = ""
ComboBox4 = ""
ComboBox5 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
TextBox11 = ""
TextBox12 = ""
TextBox13 = ""
TextBox14 = ""
TextBox15 = ""
TextBox16 = ""
TextBox17 = ""
TextBox18 = ""
TextBox19 = ""
TextBox20 = ""
TextBox1.Locked = True
TextBox2.Locked = True
ComboBox1.Locked = True
TextBox4.Locked = True
ComboBox4.Locked = True
ComboBox5.Locked = True
TextBox7.Locked = True
TextBox8.Locked = True
TextBox9.Locked = True
TextBox10.Locked = True
TextBox11.Locked = True
TextBox12.Locked = True
TextBox13.Locked = True
TextBox14.Locked = True
TextBox15.Locked = True
TextBox16.Locked = True
TextBox17.Locked = True
TextBox18.Locked = True
TextBox19Locked = True
TextBox20.Locked = True

End If
CheckBox1.Value = False
ActiveWorkbook.Save
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me
Ingproveedores.Show
End Sub

Private Sub Label15_Click()

End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub UserForm_Initialize()
CheckBox1.Value = True

Dim rango, celda As Range
Dim rango1, celda1 As Range
Dim rango2, celda2 As Range

Set rango = Range("BA3:BA40")
Set rango1 = Range("BC3:BC5")
Set rango2 = Range("BE3:BE12")

For Each celda In rango
ComboBox1.AddItem celda.Value
Next celda

For Each celda1 In rango1
ComboBox4.AddItem celda1.Value
Next celda1
For Each celda2 In rango2
ComboBox5.AddItem celda2.Value
Next celda2

End Sub

Veo que tiene dos buscardores para cam, biarlo a textbox seria así

var3 = textBox.value
Cells.Find(What:=textBox.Value, After:=ActiveCell, LookIn:=xlFormulas, lookat:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate

var2 = textBox.value
Cells.Find(What:=textBox.Value, After:=ActiveCell, LookIn:=xlFormulas, lookat:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate

Recuerda que los textbox tiene un numero no le puse en la intrucion por que no se cual seria el que usarías

Hola Aneudys, la búsqueda funciona y también trae la información al formulario, pero no habilita el botón Modificar(CommandButton1), ¿podrías ayudarme con eso?. Así quedó mi código, modifiqué algunas cosas, debo haber cometido algún error por ahí:

Private Sub TextBox21_Change()

var2 = TextBox21.Value

Cells.Find(What:=TextBox21.Value, After:=ActiveCell, LookIn:=xlFormulas, lookat:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
TextBox2 = ActiveCell.Offset(0, 1)
ComboBox1 = ActiveCell.Offset(0, 2)
TextBox4 = ActiveCell.Offset(0, 3)
ComboBox4 = ActiveCell.Offset(0, 4)
ComboBox5 = ActiveCell.Offset(0, 5)
TextBox7 = ActiveCell.Offset(0, 6)
TextBox8 = ActiveCell.Offset(0, 7)
TextBox9 = ActiveCell.Offset(0, 8)
TextBox10 = ActiveCell.Offset(0, 9)
TextBox11 = ActiveCell.Offset(0, 10)
TextBox12 = ActiveCell.Offset(0, 11)
TextBox13 = ActiveCell.Offset(0, 12)
TextBox14 = ActiveCell.Offset(0, 13)
TextBox15 = ActiveCell.Offset(0, 14)
TextBox16 = ActiveCell.Offset(0, 15)
TextBox17 = ActiveCell.Offset(0, 16)
TextBox18 = ActiveCell.Offset(0, 17)
TextBox19 = ActiveCell.Offset(0, 18)
TextBox20 = ActiveCell.Offset(0, 19)
TextBox2.Locked = False
ComboBox1.Locked = False
TextBox4.Locked = False
ComboBox4.Locked = False
ComboBox5.Locked = False
TextBox7.Locked = False
TextBox8.Locked = False
TextBox9.Locked = False
TextBox10.Locked = False
TextBox11.Locked = False
TextBox12.Locked = False
TextBox13.Locked = False
TextBox14.Locked = False
TextBox15.Locked = False
TextBox16.Locked = False
TextBox17.Locked = False
TextBox18.Locked = False
TextBox19.Locked = False
TextBox20.Locked = False

End Sub

Private Sub CommandButton1_Click()
Sheets("2016").Activate

ActiveCell.Offset(0, 1) = TextBox2.Value
ActiveCell.Offset(0, 2) = ComboBox1.Value
ActiveCell.Offset(0, 3) = TextBox4.Value
ActiveCell.Offset(0, 4) = ComboBox4.Value
ActiveCell.Offset(0, 5) = ComboBox5.Value
ActiveCell.Offset(0, 6) = TextBox7.Value
ActiveCell.Offset(0, 7) = TextBox8.Value
ActiveCell.Offset(0, 9) = TextBox9.Value
ActiveCell.Offset(0, 9) = TextBox10.Value
ActiveCell.Offset(0, 10) = TextBox11.Value
ActiveCell.Offset(0, 11) = TextBox12.Value
ActiveCell.Offset(0, 12) = TextBox13.Value
ActiveCell.Offset(0, 13) = TextBox14.Value
ActiveCell.Offset(0, 14) = TextBox15.Value
ActiveCell.Offset(0, 15) = TextBox16.Value
ActiveCell.Offset(0, 16) = TextBox17.Value
ActiveCell.Offset(0, 17) = TextBox18.Value
ActiveCell.Offset(0, 18) = TextBox19.Value
ActiveCell.Offset(0, 19) = TextBox20.Value
MsgBox "Datos actualizados correctamente", vbInformation, "Registro"
TextBox21 = ""
TextBox2 = ""
ComboBox1 = ""
TextBox4 = ""
ComboBox4 = ""
ComboBox5 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
TextBox11 = ""
TextBox12 = ""
TextBox13 = ""
TextBox14 = ""
TextBox15 = ""
TextBox16 = ""
TextBox17 = ""
TextBox18 = ""
TextBox19 = ""
TextBox20 = ""

TextBox2.Locked = True
ComboBox1.Locked = True
TextBox4.Locked = True
ComboBox4.Locked = True
ComboBox5.Locked = True
TextBox7.Locked = True
TextBox8.Locked = True
TextBox9.Locked = True
TextBox10.Locked = True
TextBox11.Locked = True
TextBox12.Locked = True
TextBox13.Locked = True
TextBox14.Locked = True
TextBox15.Locked = True
TextBox16.Locked = True
TextBox17.Locked = True
TextBox18.Locked = True
TextBox19.Locked = True
TextBox20.Locked = True
Else

ActiveCell.Offset(0, 1) = TextBox2.Value
ActiveCell.Offset(0, 2) = ComboBox1.Value
ActiveCell.Offset(0, 3) = TextBox4.Value
ActiveCell.Offset(0, 4) = ComboBox4.Value
ActiveCell.Offset(0, 5) = ComboBox5.Value
ActiveCell.Offset(0, 6) = TextBox7.Value
ActiveCell.Offset(0, 7) = TextBox8.Value
ActiveCell.Offset(0, 8) = TextBox9.Value
ActiveCell.Offset(0, 9) = TextBox10.Value
ActiveCell.Offset(0, 10) = TextBox11.Value
ActiveCell.Offset(0, 11) = TextBox12.Value
ActiveCell.Offset(0, 12) = TextBox13.Value
ActiveCell.Offset(0, 13) = TextBox14.Value
ActiveCell.Offset(0, 14) = TextBox15.Value
ActiveCell.Offset(0, 15) = TextBox16.Value
ActiveCell.Offset(0, 16) = TextBox17.Value
ActiveCell.Offset(0, 17) = TextBox18.Value
ActiveCell.Offset(0, 18) = TextBox19.Value
ActiveCell.Offset(0, 19) = TextBox20.Value


MsgBox "Datos actualizados correctamente", vbInformation, "Registro"
TextBox21 = ""
TextBox2 = ""
ComboBox1 = ""
TextBox4 = ""
ComboBox4 = ""
ComboBox5 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
TextBox11 = ""
TextBox12 = ""
TextBox13 = ""
TextBox14 = ""
TextBox15 = ""
TextBox16 = ""
TextBox17 = ""
TextBox18 = ""
TextBox19 = ""
TextBox20 = ""
TextBox21.Locked = True
TextBox2.Locked = True
ComboBox1.Locked = True
TextBox4.Locked = True
ComboBox4.Locked = True
ComboBox5.Locked = True
TextBox7.Locked = True
TextBox8.Locked = True
TextBox9.Locked = True
TextBox10.Locked = True
TextBox11.Locked = True
TextBox12.Locked = True
TextBox13.Locked = True
TextBox14.Locked = True
TextBox15.Locked = True
TextBox16.Locked = True
TextBox17.Locked = True
TextBox18.Locked = True
TextBox19Locked = True
TextBox20.Locked = True

ActiveWorkbook.Save
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me
Ingproveedores.Show
End Sub

Private Sub Label15_Click()

End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub UserForm_Initialize()

Dim rango, celda As Range
Dim rango1, celda1 As Range
Dim rango2, celda2 As Range

Set rango = Range("BA3:BA40")
Set rango1 = Range("BC3:BC5")
Set rango2 = Range("BE3:BE12")

For Each celda In rango
ComboBox1.AddItem celda.Value
Next celda

For Each celda1 In rango1
ComboBox4.AddItem celda1.Value
Next celda1
For Each celda2 In rango2
ComboBox5.AddItem celda2.Value
Next celda2

End Sub

Disculpa la tardanza

Estuve buscando desde donde locked el botón y no lo pude ver te recomiendo que use enable para las botones así veras el cambio cuando no este activado o si estas desactivado.

Private Sub TextBox21_Change()

If textBox21  <>  "" Then
CommandButton1.locked = false

end if

var2 = TextBox21.Value

Cells.Find(What:=TextBox21.Value, After:=ActiveCell, LookIn:=xlFormulas, lookat:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate

...

Recuerda valorar la pregunta para cerrarla si te silve

Hola Aneudys, ahora si actualiza los datos pero luego de mostrar el mensaje "Datos Actualizados Correctamente" queda deshabilitado el formulario.

Después del mensaje en estas parte le dice que lo limpie

MsgBox "Datos actualizados correctamente", vbInformation, "Registro"
TextBox21 = ""
TextBox2 = ""

...........

En esta otra parte le dice que lo deshabilite osea estas bloqueando los textbox para no escritura

TextBox21.Locked = True
TextBox2.Locked = True
ComboBox1.Locked = True
TextBox4.Locked = True

Si quiere seguir modificando tendrás que borrar esa parte donde lo bloquea y ponerla en otro lado con otra untrucion

acabo de percatarme que solo me modifica el ultimo registro, los demás no.

Revisa tu macro donde copia a ver que esta mal si no das con ella este es mi correo y a ver donde estas el error

[email protected]

Escribe numerando que es lo que encesitas

Ejemplo

1 - que le el boton este desactivado

2 - que se active cuando tenga dasto

Y asi susecivamente para hacerlo

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas