Reputation: 49
I have turned on the "require variable declare" option to force to declare the variable in the VBA setting. After recording a Macro, the following recorded Macro fails to run with an error message:
compile error: expected function or variable.
I have tried to turned off the "require variable declare" in tools->options, then the code runs successfully. How to run it when the option is on?
Option Explicit
Sub Macro2()
'
' Macro2 Macro
'
'
Range("A1:E4").Select
selection.Copy
Range("A16").Select
activesheet.Paste
End Sub
Upvotes: 0
Views: 380
Reputation: 1126
VBA is case sensitive. selection.Copy should be Selection.Copy and activesheet.Paste should be ActiveSheet.Paste. Also, unless there is a need to select the cells, you can simplify your code to:
Range("A1:E4").Copy Range("A16")
Upvotes: 1