I have a folder full of Workbooks and I have a Master Summary Workbook. The code below searches through the folder and records any rows that meet Criteria "Yes" in column K from the folder full of Workbooks (Sheet: Data) and copies the rows to the Master Summary Workbook (Sheet: CapEx).
However, I keep getting "A formula or sheet you want to move or copy contains the name "...", which already exists on the destination worksheet." I don't have any name ranges or objects in the Master Summary Workbook and I am forced to keep clicking "Yes" through all message boxes until it cycles through all the Workbooks.
So, how would I edit the code below to "only copy values" from the other Workbooks without getting this error. Thanks in advance.
However, I keep getting "A formula or sheet you want to move or copy contains the name "...", which already exists on the destination worksheet." I don't have any name ranges or objects in the Master Summary Workbook and I am forced to keep clicking "Yes" through all message boxes until it cycles through all the Workbooks.
So, how would I edit the code below to "only copy values" from the other Workbooks without getting this error. Thanks in advance.
Code:
Sub CopyCapEx()
Application.ScreenUpdating = False
'Display Open Dialog to select file directory
filenames = Application.GetOpenFilename("Excel Files (*.xls*)," & _
"*.xls*", 1, "Select Files", "Open", False)
'If the user cancels file selection then exit
If TypeName(filenames) = "Boolean" Then
Exit Sub
End If
'Set xls as SourceFile
SourceFile = Dir("*.xls*")
Do While SourceFile <> ""
If Not (SourceFile) = "Master Summary.xlsm" Then
Workbooks.Open (SourceFile)
Set XLSFile = ActiveWorkbook
With Sheets("Data")
LR = .Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
If .Range("K" & i).Value = "Yes" Then
j = j + 1
.Range("A" & i & ":K" & i).Copy Destination:=Workbooks("Master Summary.xlsm").Sheets("CapEx").Range("A" & j)
End If
Next i
Windows.Application.CutCopyMode = False
XLSFile.Close False
End With
End If
SourceFile = Dir
Loop
Application.ScreenUpdating = True
End Sub