VBA macro work only when workbook is activated

NileshAPatel

New Member
Joined
May 29, 2021
Messages
26
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi everyone

I had prepared one macro which is working fine one source file is activated but it doesn't work when destination file is active not source. (Both files are open)
Is there any way that when Master file is active and data get copied from CustomerOrderReport file and paste in master file.

This macro is running fine when I select CustomerOrderReport file as active and showing on screen
but didn't work when Master file is active and showing on screen

Sub test()
'Copy paste only values
Workbooks("CustomerOrderReport.xls").ActiveSheet.Range(Range("A3").End(xlToRight), Range("A3").End(xlDown)).Copy
Workbooks("Master").Worksheets("Today").Range("D1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub



Thanks in advance
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How about
VBA Code:
Sub test()
'Copy paste only values
With Workbooks("CustomerOrderReport.xls").ActiveSheet
   .Range(.Range("A3").End(xlToRight), .Range("A3").End(xlDown)).Copy
   Workbooks("Master").Worksheets("Today").Range("D1").PasteSpecial Paste:=xlPasteValues
   Application.CutCopyMode = False
End With
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub test()
'Copy paste only values
With Workbooks("CustomerOrderReport.xls").ActiveSheet
   .Range(.Range("A3").End(xlToRight), .Range("A3").End(xlDown)).Copy
   Workbooks("Master").Worksheets("Today").Range("D1").PasteSpecial Paste:=xlPasteValues
   Application.CutCopyMode = False
End With
End Sub
Thanks for quick reply

Error is showing "Run-time error '1004' Application-defined or object-defined error


Regards
 
Upvote 0
Thanks for quick reply

Error is showing "Run-time error '1004' Application-defined or object-defined error


Regards
I am very much sorry, it's work perfactly...
I did a mistake in editing my code which later on i compare with your and found mistake.

Thanks once again for your quick and grateful support.

Regards
Nilesh Patel 🙏
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top