Greenhillchris
New Member
Hi
Looking for some advice on my vba code and why I am getting errors.
What I am trying to do is open an excel workbook and copy and paste that information into another workbook and repeat that multiple times for different workbooks using direct file paths.
I have the file paths of the workbooks I want to open and copy data from in column B. In column C I have the file paths to open that workbook and paste the data in. Example: file path in B2 & C2 would open and data copied from file path B2 to C2.
Here’s my code
>>> use code - tags <<<
I am getting an error of runtime error 438 object doesn’t support this property or method at this stage and wondering why
Thanks
Looking for some advice on my vba code and why I am getting errors.
What I am trying to do is open an excel workbook and copy and paste that information into another workbook and repeat that multiple times for different workbooks using direct file paths.
I have the file paths of the workbooks I want to open and copy data from in column B. In column C I have the file paths to open that workbook and paste the data in. Example: file path in B2 & C2 would open and data copied from file path B2 to C2.
Here’s my code
>>> use code - tags <<<
Code:
Public Sub OpenCopyClose()
Dim WB1 As Range, WB2 As Range
Dim ws1 As Worksheet, ws2 As Worksheet
Set WB1 = ActiveSheet.Range("B2", ActiveSheet.Range("B2").End(xlDown)) 'Source file paths
Set WB2 = ActiveSheet.Range("C2", ActiveSheet.Range("C2").End(xlDown)) 'Destination file paths
Set ws1 = WB1.Sheets("Tracker") ' Source name of Sheet
Set ws2 = WB2.Sheets("Tracker") 'Desination name of Sheet
With Application
.DisplayAlerts = False
.ScreenUpdating = False
.EnableEvents = False
.AskToUpdateLinks = False
End With
For Each Workbook In WB1
Workbooks.Open Filename:=WB1
Workbooks.Open Filename:=WB2
ws1.Range("b6:Y25").Copy 'source
ws2.Range("B").PasteSpecial xlPasteValues 'destination
WB1.Close SaveChanges:=True
WB2.Close SaveChanges:=True
Next
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.EnableEvents = True
.AskToUpdateLinks = True
End With
End Sub
Code:
Set ws1 = WB1.Sheets("Tracker") ' Source name of Sheet
Thanks
Last edited by a moderator: