Hey, guys.
I am creating a VBA macro that combines spreadsheets that are within a folder picking up the data and joining them all into another spreadsheet. They have the same columns, but with different data.
My code:
The data that supplies the main spreadsheet must be entered one below the other starting from the first empty row. But when I run the macro the data is inserted below the other but the repetition of the data table occurs.
But there is a problem. The image below shows the detail:
The main table is also being copied, but it shouldn't. Only the ones I added.
Example of how are the spreadsheets I'm getting the data:
And how the sheets are:
Would anyone know how to explain to me how to solve this problem of data duplication?
I am creating a VBA macro that combines spreadsheets that are within a folder picking up the data and joining them all into another spreadsheet. They have the same columns, but with different data.
My code:
VBA Code:
Sub ConslidateWorkbooks()
Dim verificador As Boolean
Dim celula As String
Path = "C:\dev\"
Filename = Dir(Path & "*.xlsx")
'Application.DisplayAlerts = False
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
For Each aba In ThisWorkbook.Sheets
If aba.Name <> "Dados" Then
MsgBox aba.Name
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Dados").Select
linha = Range("A1048576").End(xlUp).Row + 1
Cells(linha, 3).Select
ActiveSheet.Paste
End If
Next
Loop
Application.DisplayAlerts = True
End Sub
The data that supplies the main spreadsheet must be entered one below the other starting from the first empty row. But when I run the macro the data is inserted below the other but the repetition of the data table occurs.
But there is a problem. The image below shows the detail:
The main table is also being copied, but it shouldn't. Only the ones I added.
Example of how are the spreadsheets I'm getting the data:
And how the sheets are:
Would anyone know how to explain to me how to solve this problem of data duplication?