I'm stuck in a problem in VBA while consolidating data from other workbook to master work book and using file name and path name is variable which is changing dynamically in loop i searched but i only find hard coded path so i'm posting here following is my code.
Sub Append()
'Append data from other files
Path = "E:\NPM PahseIII\"
Dim c As Range
'find the first empty cell in ColA
Set c = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(2, 0)
Filename = Dir(Path & "*.xlsx")
Do While Filename <> ""
If InStr(Filename, ".") > 0 Then
Filenamenoext = Left(Filename, InStr(Filename, ".") - 1)
End If
c.Value = Filenamenoext
Set c = c.Offset(1, 0)
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
Windows("Master sheet").Activate
Selection.Consolidate Sources:=Array("'Path & [Filename]Sheet1'!$B$2:$B$5"),
Function:=xlSummary
Workbooks(Filename).Close
Filename = Dir()
Loop
End Sub
The first problem is that this program gives me the error
Object doesn't support this property or method
at this line
Selection.Consolidate Sources:=Array("'Path & [Filename]Sheet1'!$B$2:$B$5"),
Function:=xlSummary
secondly i want that when first time data is appended by running the code again if there is no change in the other files data then code should not append duplicate again.