|
Hola, voy a suponer que el nombre de tus Libros son Libro Base y Libro Formulario (tus los cambias), en el Textbox1 pones el nombre a buscar, el Textbox2 te muestra el Nro de Cliente, TextBox3 te pone los datos concatenados.
1º Codigo en el Userform1:
Private Sub Userform1_Initialize()
ChDir "C:\Documents and Settings\Usuario\Escritorio"
Workbooks.Open Filename:= _
"C:\Documents and Settings\Usuario\Escritorio\Libro Base.xls"
End Sub
'Cambia el usuario y la ruta donde se encuentra el Libro Base
2º Codigo en el TextBox1:
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Range("A1").Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Find(What:=TextBox1, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
celda = ActiveCell.Address
ListBox1.AddItem ActiveCell.Value
Selection.FindNext(After:=ActiveCell).Activate
Do While ActiveCell.Address <> celda
ListBox1.AddItem ActiveCell.Value
Selection.FindNext(After:=ActiveCell).Activate
Loop
End Sub
'Pones en el Textbox1 un nombre y al pulsar enter se te llenara el Listbox1 con la lista de todos los nombres que contengan esas letras
3º Codigo en el boton Buscar (CommandButton1)
Private Sub CommandButton1_Click()
Range("A1").Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
If ListBox1.Text = "" Then
MsgBox "Debe seleccionar un valor en la lista"
Exit Sub
End If
Selection.Find(What:=ListBox1, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
TextBox2.Value = ActiveCell.Offset(0, 1).Value
TextBox3.Value = ActiveCell.Value & " " & ActiveCell.Offset(0, 1).Value & " " &ActiveCell.Offset(0,2).Value & " " & ActiveCell.Offset(0, 3).Value& " " & ActiveCell.Offset(0, 4).Value& " " & ActiveCell.Offset(0, 5).Value& " " & ActiveCell.Offset(0, 6).Value& " " & ActiveCell.Offset(0, 7).Value& " " & ActiveCell.Offset(0, 8).Value
End Sub
'Si no has elegido un valor del Listbox1 te lanzará un aviso para que elijas uno y vuelvas a pulsar el boton buscar, te pondrá en el TextBox2 el numero de cliente y en el TextBox3 la concatenacion de las celdas de esa fila.
Y ahora un segundo boton para limpiar todo y volver a buscar:
Private Sub CommandButton2_Click()
TextBox1.Value = Empty
TextBox2.Value = Empty
TextBox3.Value = Empty
ListBox1.Clear
End Sub
A ver si te va sirviendo.
>Un saludo
>Julio
|