Clairexcel
New Member
- Joined
- Mar 23, 2021
- Messages
- 31
- Office Version
- 2016
- 2010
Hello again everyone,
I have another VBA code that I have been trying to adapt to my needs (it is a code I found so I did not write it) that should transfer data from 4 workbooks (all in the same folder) into master workbook.
Now every workbook has the same name on sheet 1 which is the sheet that has to be copied into the masterbook on a sheet with also the same name.
It works perfectly the first time, but if I click the command button again to refresh the data (that other users may have added in their workbooks meanwhile), it copies again all the data bellow the occupied rows. That means I have double entries of data, and if I click a third time the macro button it copie below alla the data , so then I would have three times the same data..
Could anyone please tell me what should I modify so that whenever one clicks the command button with the macro can get the all data from the other workbooks without repeating it...I hope I explained myself.
Another issue I have is that it copies the headers from all the sheets, but I want it to only cpoy data without the headers, because in the masterworkbook/mastersheet I already have the headers. I tried tweaking the Offset of the UsedRange but if I set it to (2) it will leave out the first used row when it transfers the data to master wkbk
Here is the code I have:
Thank you in advance for any help or suggestions.
I have another VBA code that I have been trying to adapt to my needs (it is a code I found so I did not write it) that should transfer data from 4 workbooks (all in the same folder) into master workbook.
Now every workbook has the same name on sheet 1 which is the sheet that has to be copied into the masterbook on a sheet with also the same name.
It works perfectly the first time, but if I click the command button again to refresh the data (that other users may have added in their workbooks meanwhile), it copies again all the data bellow the occupied rows. That means I have double entries of data, and if I click a third time the macro button it copie below alla the data , so then I would have three times the same data..
Could anyone please tell me what should I modify so that whenever one clicks the command button with the macro can get the all data from the other workbooks without repeating it...I hope I explained myself.
Another issue I have is that it copies the headers from all the sheets, but I want it to only cpoy data without the headers, because in the masterworkbook/mastersheet I already have the headers. I tried tweaking the Offset of the UsedRange but if I set it to (2) it will leave out the first used row when it transfers the data to master wkbk
Here is the code I have:
VBA Code:
Sub Vedipratiche()
Dim wb As String
Application.ScreenUpdating = False
wb = Dir(ThisWorkbook.Path & "\*")
Do Until wb = ""
If wb <> ThisWorkbook.Name Then
Workbooks.Open ThisWorkbook.Path & "\" & wb
'offset 4 value tells to which row in the master workbook to start copying
With Workbooks(wb).Sheets(1)
.UsedRange.Offset(1).Copy ThisWorkbook.Sheets("Aggiornapratiche").Cells(Rows.Count, 1).End(xlUp).Offset(1)
End With
Application.CutCopyMode = False
Workbooks(wb).Close False
End If
wb = Dir
Loop
Application.ScreenUpdating = True
End Sub