Hankthetanker
New Member
- Joined
- May 12, 2016
- Messages
- 4
Hi Excel PROs
I need some help. I'm trying to paste values from all files in a folder to a master folder but i keep getting errors in the paste process. This is my code:
Sub LoopThrough()Dim MyFile As String
Dim erow
Dim FilePath As String
Dim DestWB As Workbook
Dim SourceWB As Workbook
'this way we know the one where the code is running and the destination for our copies
Set DestWB = ThisWorkbook
FilePath = "C:\data\"
MyFile = Dir(FilePath)
Do While Len(MyFile) > 0
If MyFile = "Master.xlsm" Then
Exit Sub
End If
Set SourceWB = Workbooks.Open(FilePath & MyFile)
Workbooks.Open (FilePath & MyFile)
Range("A1:L51").Copy
'Move the close to AFTER you do the paste
'NOTE: You may have to make a change here:
DestWB.Range(Cells(erow, 1), Cells(erow, 12)).PasteSpecial xlValues
SourceWB.Close False
MyFile = Dir
Loop
End Sub
Can i please get some help?
I need some help. I'm trying to paste values from all files in a folder to a master folder but i keep getting errors in the paste process. This is my code:
Sub LoopThrough()Dim MyFile As String
Dim erow
Dim FilePath As String
Dim DestWB As Workbook
Dim SourceWB As Workbook
'this way we know the one where the code is running and the destination for our copies
Set DestWB = ThisWorkbook
FilePath = "C:\data\"
MyFile = Dir(FilePath)
Do While Len(MyFile) > 0
If MyFile = "Master.xlsm" Then
Exit Sub
End If
Set SourceWB = Workbooks.Open(FilePath & MyFile)
Workbooks.Open (FilePath & MyFile)
Range("A1:L51").Copy
'Move the close to AFTER you do the paste
'NOTE: You may have to make a change here:
DestWB.Range(Cells(erow, 1), Cells(erow, 12)).PasteSpecial xlValues
SourceWB.Close False
MyFile = Dir
Loop
End Sub
Can i please get some help?