ExcelVBNoob
New Member
- Joined
- Jul 11, 2020
- Messages
- 4
Hi Hope you guys can help,
1) I open a new workbook that i do not save.
2) I open a second workbook that contains the name "SALES" in the filename.
3) I want some VBA code to copy data from the "SALES" file into the file that i initially opened.
So far i have the below and it works up until i get to the point of copying the data. It fails to switch back to the original workbook and paste the data.
+++++++++++++++++++++++++++++++
Dim wbkMain
Set wbkMain = ThisWorkbook
Dim wb As Workbook
For Each wb In Application.Workbooks
If wb.Name Like "*SALES*" Then
wb.Activate
Exit For
End If
Next wb
ActiveWorkbook.ActiveSheet.Range("A1:R6788").Copy
ThisWorkbook.Activate
wbkMain.Activate
ActiveSheet.Paste
+++++++++++++++++++++++++++++++
What am i doing wrong?
1) I open a new workbook that i do not save.
2) I open a second workbook that contains the name "SALES" in the filename.
3) I want some VBA code to copy data from the "SALES" file into the file that i initially opened.
So far i have the below and it works up until i get to the point of copying the data. It fails to switch back to the original workbook and paste the data.
+++++++++++++++++++++++++++++++
Dim wbkMain
Set wbkMain = ThisWorkbook
Dim wb As Workbook
For Each wb In Application.Workbooks
If wb.Name Like "*SALES*" Then
wb.Activate
Exit For
End If
Next wb
ActiveWorkbook.ActiveSheet.Range("A1:R6788").Copy
ThisWorkbook.Activate
wbkMain.Activate
ActiveSheet.Paste
+++++++++++++++++++++++++++++++
What am i doing wrong?