Hi Excel Community,
Please note I am trying to consolidate data through VBA, I am still learning regarding VBA so appreciate your help. ( Note: The solution cannot be using power query)
Basically I need to open like 12 excel files and see if the sheets("Template") (Same name sheet is in all workbooks) , if has data from row 2 to end then copy and paste into the master files (Master)
and then do the same for the rest of the files but probably from the second file data will paste in the next row in blank.
I guess maybe this code can explain you better the idea.
Regards
Andres
Please note I am trying to consolidate data through VBA, I am still learning regarding VBA so appreciate your help. ( Note: The solution cannot be using power query)
Basically I need to open like 12 excel files and see if the sheets("Template") (Same name sheet is in all workbooks) , if has data from row 2 to end then copy and paste into the master files (Master)
and then do the same for the rest of the files but probably from the second file data will paste in the next row in blank.
VBA Code:
'Option Private Module
Sub Extraction()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.AskToUpdateLinks = False
.EnableEvents = False
Dim Master As Workbook
Set Master = ThisWorkbook
On Error Resume Next
'________________________________________________________________________________________________________X1
Workbooks.Open Filename:="L:\2022\XXX\X1\Template.xlsm"
Sheets("Rule").Select
'If Range("E2") <> Empty Then ' I was trying to do it but I cannot find a solution to avoid leaving data
Rows("2:25000").Select
Selection.Copy
Master.Activate
Sheets("Changes Required").Select
Selection.Range("A2").PasteSpecial
Workbooks("Template").Close savechanges:=False
'End If
'________________________________________________________________________________________________________X2
Workbooks.Open Filename:="L:\2022\XXX\X2\Template.xlsm"
Sheets("Rule").Select
'If Range("E2") <> Empty Then ' I was trying to do it but I cannot find a solution to avoid leaving data
Rows("2:25000").Select
Selection.Copy
Master.Activate
Sheets("Changes Required").Select
'___________________________________________________________Copy data in the next blank row
Range("F" & Rows.Count).End(xlUp).Offset(1, -5).PasteSpecial
Workbooks("Template").Close savechanges:=False
'End If
'________________________________________________________________________________________________________X3
Workbooks.Open Filename:="L:\2022\XXX\X3\Template.xlsm"
Sheets("Rule").Select
'If Range("E2") <> Empty Then ' I was trying to do it but I cannot find a solution to avoid leaving data
Rows("2:25000").Select
Selection.Copy
Master.Activate
Sheets("Changes Required").Select
'___________________________________________________________Copy data in the next blank row
Range("F" & Rows.Count).End(xlUp).Offset(1, -5).PasteSpecial
Workbooks("Template").Close savechanges:=False
'End If
'_______________________________________________________________________________________________________
.ScreenUpdating = True
.DisplayAlerts = True
.AskToUpdateLinks = True
.EnableEvents = True
End With
End Sub
I guess maybe this code can explain you better the idea.
Regards
Andres