All of a sudden, all macros are now failing due to Compile error: Expected Function or variable

haganator2112

New Member
Joined
Feb 28, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I've been using these macros for months and recently every single macro that I normally use is failing due to the Compile error: Expected Function or variable. I sent the below script to a coworker and they were able to run it on their system with no issues.

Sub Cleaner_Surveillance()
'
' Cleaner_Surveillance Macro
'
Columns("A:A").Select
Range("A6").Activate
Range(selection, selection.End(xlToRight)).Select -> It highlights the 1st "selection" for all macros. Should "selection" be capitalized? I tried to manually change this but it won't save it.
selection.ColumnWidth = 123.86
Columns("A:F").EntireColumn.AutoFit
Cells.Select
Cells.EntireRow.AutoFit
Rows("6:6").Select
selection.AutoFilter
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1:F1").Select
'
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Do you have another macro in the workbook called Sub Selection()
If so, rename that macro !
 
Upvote 0
Solution
Do you have another macro in the workbook called Sub Selection()
If so, rename that macro !
BOOM! Genius! I forgot I was capturing a "selection" sequence for another macro and forgot to delete it. Thank you so much! Tidying up after yourself definitely has its advantages.
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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