Macro para extraer informacion de varias hojas y consolidarlas en un nuevo libro

JORGEMELS

New Member
Joined
Apr 25, 2014
Messages
13
Hola, estoy iniciandome en esto pero no encuentro sintaxis en ningun lado espero pueda encontrar ayuda aqui, tengo un libro con varias hojas de calculo A1, A2, A3, A4, y tengo informacion en tablas de cada una y necesito un macro para poder seleccionar el rango de ellas y consolidar la informacion en otro archivo, es decir que el macro diga :

Ingresar rango deseado de hojas

yo pondria por ejemplo de A31 a A34

y que me consolide en una nueva hoja de calculo llamada consolidado

Ejemplo:

ejemplo - YouTube
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Utiliza esta macro para resolver el problema que usd tiene.

Lo siento para mal esponal como ya aprendiendo esta lengua.

Code:
Sub CopiarPegarTablas()

    Dim n As Worksheet
    Dim curWB, newWB As Workbook
    
    curWB = ThisWorkbook.Name
    
    Workbooks.Add
    newWB = ThisWorkbook.Name
    
    curWB.Activate

    For Each n In Worksheets ' Loop para selectionar varias hojas
        n.Select
        If Application.WorksheetFunction.CountA(Range("C:C")) > 1 Then ' condicion para prueba si datos existan en tablas
            Range("B11:I" & Range("I65536").End(xlUp).Row).Copy
            newWB.Activate
            Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
            curWB.Activate
        End If
    Next n

End Sub
 
Upvote 0
prueba esta code...

esta macro no va a funcionar para hidden hojas

Code:
Sub CopiarPegarTablas()

    Dim n As Integer
    Dim curWB As String
    Dim newWB As String
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    curWB = ThisWorkbook.Name
    
    Workbooks.Add
    newWB = ActiveWorkbook.Name
    
    Workbooks(curWB).Activate

    For n = 31 To 34 ' Loop para selectionar varias hojas * cambio para diferente numero del hojas
        Sheets("A" & n).Select
        If Application.WorksheetFunction.CountA(Range("C:C")) > 1 Then ' condicion para prueba si datos existan en tablas
            Range("C11:I" & Range("I65536").End(xlUp).Row).Copy
            Workbooks(newWB).Activate
            Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
            Workbooks(curWB).Activate
        End If
    Next n

    Workbooks(newWB).Activate
    Range("A1:A" & Range("A65536").End(xlUp).Row).AutoFilter Field:=1, Criteria1:=""
    Range("A3:A" & Range("A65536").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Select
    Selection.Rows.Delete
    ActiveSheet.AutoFilterMode = False
    
    Columns("B:B").NumberFormat = "m/d/yyyy h:mm"

End Sub
 
Upvote 0
asi es como funciona cierto?

Code:
Sub CopiarPegarTablas()

    Dim n As Integer
    Dim curWB As String
    Dim newWB As String
    
    Application.ScreenUpdating = False ' comando para evitar que se actualice la informacion?
    Application.DisplayAlerts = False ' coomando para evitar que se mande un error?
    
    curWB = ThisWorkbook.Name
    
    Workbooks.Add ' agregar libro
    newWB = ActiveWorkbook.Name
    
    Workbooks(curWB).Activate ' activar current workbook


    For n = 34 To 36 ' Loop para selectionar varias hojas * cambio para diferente numero del hojas
        Sheets("A" & n).Select
        If Application.WorksheetFunction.CountA(Range("C:C")) > 1 Then ' condicion para prueba si datos existan en tablas
            Range("C11:I" & Range("I65536").End(xlUp).Row).Copy ' seleccionar el rango deseado siempre y cuando existan datos
            Workbooks(newWB).Activate
            Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
            Workbooks(curWB).Activate
        End If
    Next n


    Workbooks(newWB).Activate
    Range("A1:A" & Range("A65536").End(xlUp).Row).AutoFilter Field:=1, Criteria1:="" ' pegar datos en la hoja y dejar la primera fila en blanco
    Range("A3:A" & Range("A65536").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Select ' quitar blancos
    Selection.Rows.Delete
    ActiveSheet.AutoFilterMode = False
    
    Columns("B:B").NumberFormat = "m/d/yyyy h:mm"


End Sub
 
Upvote 0
De nada!

La primera fila es blanco porque esta code. La foncionar de "Offset(1,0)" causa primera fila ser blancos

Code:
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

Tambien...
Code:
Range("A1:A" & Range("A65536").End(xlUp).Row).AutoFilter Field:=1, Criteria1:="" ' esta code pone "Filter" en la tabla y mostra filas entre diferent varias tablas que estan blancos
Range("A3:A" & Range("A65536").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Select ' selecionando filas/cildas que esta visible y blanco
Selection.Rows.Delete ' quitar blancos
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top