Implicit Containing Worksheet Reference

Locates unqualified Worksheet.Range/Cells/Columns/Rows member calls inside worksheet modules, that implicitly refer to the containing sheet component.

Reasoning

Implicit references inside a worksheet document module can easily be mistaken for implicit references to the active worksheet (ActiveSheet), which is the behavior in all other module types. By explicitly qualifying these member calls with 'Me', the ambiguity can be resolved. If the intent is to refer to the active worksheet, qualify with 'ActiveSheet' to prevent a bug.

Default severity

Warning

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

Sheet1 (DocumentModule)
Private Sub Example() Dim foo As Range Set foo = Range("A1") ' Worksheet.Range implicitly from containing worksheet End Sub

This example should NOT trigger a result

Sheet1 (DocumentModule)
Private Sub Example() Dim foo As Range Set foo = Me.Range("A1") End Sub

Rubberduck.CodeAnalysis.Inspections.Concrete.ImplicitContainingWorksheetReferenceInspection.cs (Prerelease-v2.5.9.6289)