Unexpected Compile Error

mialls

New Member
Joined
Oct 27, 2010
Messages
11
Error: Compile Error - Expected Function or variable

Macro:

Sub WhiteFlag()
Range("A5").Select
Selection.EntireRow.Insert
End Sub

(The word "Selection" is highlighed in the VBA editor, hence why it is highlighted here.)


This macro worked perfectly until about an hour ago, as part of a larger macro. I tried rewriting it by hand, then separating it into its own individual macro, and finally I used the Record Macro tool, all with the same result.

The exact same Macro in an entirely new Excel file works perfectly.

Any idea's what I did to cause this and how to avoid this in the future?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Do you have a variable, sub, function or module called Selection?
 
Upvote 0
Ha. That fixed the problem, and I learned something new.

I do have a Sub named "Selection" it seems - two, in fact. (Well, the same macro in multiple locations.) First in an actual Module, and second in code for a UserForm. The Macro in the Userform code section wouldn't run properly (it would only open the Userform when I tried to run it), but it wasn't impeding any other code from running, even when the Userform was being tested.

Once I cleaned up the code section of the Userform, and copied all the code that wasn't working to a Module for investigation and testing later, that's when the problem came up.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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