Macro para buscar datos en otro libro y mostrar los datos en un formulario
Primero de todo quiero agradecerte tu ayuda.
Para finalizar el excel necesitaría si es posible una modificación del código que me hiciste. La macro busca el numero en otro libro y pega los datos de F5:F10, necesitaría que estos datos (si existen) en vez de que se pegaran en las celdas F5 a F10 se abriera un form y que apareciera el resultado de la busqueda. El problema es que no consigo que aparezcan los datos en el formularion (aparecen los campos en blanco), pero si abrirlo si el numero existe.
Sub Buscar_Numero()
'Por Dante Amor
'
'Buscar número en otro libro
'
'Datos del libro1
hoja_1 = "Buscador"
Set l1 = ThisWorkbook
Set h1 = l1.Sheets(hoja_1)
h1.Activate
numero = h1.TextBox1.Value
If numero = "" Then
MsgBox "Falta capturar el número"
'ActiveSheet.TextBox1.Activate
Exit Sub
End If
h1.Range("F5:F10").Value = ""
'
'Datos del libro2
libro2 = "datos.xlsm"
hoja_2 = "Registros enviados"
ruta2 = "H:\digitalizaciones\Expedientes tramitados\"
'ruta2 = ThisWorkbook.Path & "\"
'
If Dir(ruta2 & libro2) = "" Then
MsgBox "No existe el libro: " & libro2, vbCritical
Exit Sub
End If
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'
Set l2 = Workbooks.Open(ruta2 & libro2, UpdateLinks:=False, ReadOnly:=True)
Set h2 = l2.Sheets(hoja_2)
Set b = h2.Columns("D").Find(numero, LookIn:=xlValues, lookat:=xlWhole)
If Not b Is Nothing Then
H1. Range("F5").Value = h2. Cells(b.Row, "D")
H1. Range("F6").Value = h2. Cells(b.Row, "E")
H1. Range("F7").Value = h2. Cells(b.Row, "F")
H1. Range("F8").Value = h2. Cells(b.Row, "G")
H1. Range("F9").Value = h2. Cells(b.Row, "H")
H1. Range("F10").Value = h2. Cells(b.Row, "I")
Else
MsgBox "No existe el número : " & numero, vbExclamation
End If
l2.Close False
End Sub
1 Respuesta
Respuesta de Dante Amor
2
