greenhillchris
New Member
- Joined
- Mar 5, 2022
- Messages
- 18
- Office Version
- 365
Hi,
I have multiple workbooks which I need to copy the data over to different multiple workbooks. Each data in a workbook needs to be copied over to certain workbook and then saved and closed.
I am using specific filepaths for each workbook, so in my active workbook that I am going to run the macro from, column A has the source filepath for each workbook where the data is copied from and in column B the filepath of where the data from the source workbook should be pasted too.
I have started on the code as below but running into errors when the copying and pasting part comes into play and I still need to add the save and close code.
Granted this is probably the most backward way of doing it so was just looking for adivce on how to improve this code and to get it to work how i want it too.
Thanks
I have multiple workbooks which I need to copy the data over to different multiple workbooks. Each data in a workbook needs to be copied over to certain workbook and then saved and closed.
I am using specific filepaths for each workbook, so in my active workbook that I am going to run the macro from, column A has the source filepath for each workbook where the data is copied from and in column B the filepath of where the data from the source workbook should be pasted too.
I have started on the code as below but running into errors when the copying and pasting part comes into play and I still need to add the save and close code.
Granted this is probably the most backward way of doing it so was just looking for adivce on how to improve this code and to get it to work how i want it too.
Thanks
VBA Code:
Public Sub TrackersCopyAndPaste()
Dim documents As Range, wb As Range 'Source
Dim documentsDest As Range, wbd As Range 'Destination
Dim ws As Worksheet
Set documents = ActiveSheet.Range("A2:A12") 'Source file paths
Set documentsDest = ActiveSheet.Range("B2:B12") 'Destination file paths
With Application
.DisplayAlerts = False
.ScreenUpdating = False
.EnableEvents = False
.AskToUpdateLinks = False
End With
For Each wb In documents
Workbooks.Open Filename:=wb 'source workbooks
Next
For Each wbd In documentsDest
Workbooks.Open Filename:=wbd 'destination workbooks
Next
For Each ws In wb
wb.Range("A2:Y25").Copy 'source
wbd.Range("b2").Paste.Values 'destination
Next
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.EnableEvents = True
.AskToUpdateLinks = True
End With
End Sub