Quiero saber si es posible traer dos libros de trabajo (hoja 1) en una hoja de trabajo (libro de trabajo maestro). Necesito tener dos datos juntos en una hoja de cálculo.
Cualquier ayuda es muy apreciada. A continuación se muestran capturas de pantalla para obtener más detalles si ayuda.
Dos archivos:
Consulte el archivo adjunto para obtener más detalles si es de ayuda.
Gracias por examinar esto.
Datos del archivo 1 y del archivo 2: ambos tienen las mismas direcciones de correo electrónico.
Es importante destacar que me gustaría una macro para extraer datos para identificar o incluso hacer coincidir ambas direcciones de correo electrónico. Si lo encuentra, agréguelo a una hoja de trabajo.
Por ejemplo, en la hoja de trabajo (maestra) debe haber un archivo de datos 1 en el lado izquierdo y el archivo de datos 2 en el lado derecho, incluidos los encabezados.
Espero que puedas ver mis imágenes con claridad.
Saludos
V
Aquí hay una descripción general para comenzar:
Vba Importar archivos CSV a Excel
Propuesta: el uso de la conexión a través de PowerQuery le permite procesarlos más como tablas y también unirlos/fusionarlos en uno mientras puede ver y seguir cada paso del proceso.
Algo como esto debería hacer lo que quieras. Siéntase libre de cambiar el código para satisfacer sus necesidades.
Sub CopyRangeFromMultiWorksheets() Dim sh As Worksheet Dim DestSh As Worksheet Dim Last As Long Dim CopyRng As Range With Application .ScreenUpdating = False .EnableEvents = False End With 'Delete the sheet "RDBMergeSheet" if it exist Application.DisplayAlerts = False On Error Resume Next ActiveWorkbook.Worksheets("RDBMergeSheet").Delete On Error GoTo 0 Application.DisplayAlerts = True 'Add a worksheet with the name "RDBMergeSheet" Set DestSh = ActiveWorkbook.Worksheets.Add DestSh.Name = "RDBMergeSheet" 'loop through all worksheets and copy the data to the DestSh For Each sh In ActiveWorkbook.Worksheets If sh.Name <> DestSh.Name Then 'Find the last row with data on the DestSh Last = LastRow(DestSh) 'Fill in the range that you want to copy Set CopyRng = sh.Range("A1:G1") 'Test if there enough rows in the DestSh to copy all the data If Last + CopyRng.Rows.Count > DestSh.Rows.Count Then MsgBox "There are not enough rows in the Destsh" GoTo ExitTheSub End If 'This example copies values/formats, if you only want to copy the 'values or want to copy everything look at the example below this macro CopyRng.Copy With DestSh.Cells(Last + 1, "A") .PasteSpecial xlPasteValues .PasteSpecial xlPasteFormats Application.CutCopyMode = False End With 'Optional: This will copy the sheet name in the H column DestSh.Cells(Last + 1, "H").Resize(CopyRng.Rows.Count).Value = sh.Name End If Next ExitTheSub: Application.Goto DestSh.Cells(1) 'AutoFit the column width in the DestSh sheet DestSh.Columns.AutoFit With Application .ScreenUpdating = True .EnableEvents = True End With End SubFunción LastRow(sh como hoja de trabajo) En caso de error Reanudar Next LastRow = sh.Cells.Find(What:="*", _ After:=sh.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas , _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Row On Error GoTo 0 End Function
Función LastCol(sh como hoja de trabajo) En caso de error Reanudar Next LastCol = sh.Cells.Find(What:="*", _ After:=sh.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas , _ SearchOrder:=xlByColumns, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Column On Error GoTo 0 End Function
Código fuente:
https://www.rondebruin.nl/win/s3/win002.htm
Además, echa un vistazo a esto.