Skip to content

Inspection for use of SpecialCells with single cell reference, or a sheet.cells reference #3759

Open
@ThunderFrame

Description

@ThunderFrame

As per Range SpecialCells ClearContents clears whole sheet instead and Determine if cell contains data validation

Range({any single cell}).SpecialCells({whatever}) seems to work off the entire sheet.
Range({more than one cell}).SpecialCells({whatever}) seems to work off the specified cells.

and

If the Range object on which you call SpecialCells represents only a single cell, the entire sheet will be scanned to find matches. If you have a very large amount of data, the methods provided in previous answers may become a bit slow.

Rubberduck should have an inspection for usages of SpecialCells where either:

  1. The range object is a single cell, or refers to an address that resolves to a single cell, or;

  2. A Range is Intersected with all of the cells on a sheet: Sheet.Cells.SpecialCells, eg (from https://www.pcreview.co.uk/threads/testing-for-cell-validation.991949/, but corrected):

Dim Cell As Range
Set cell = Range("B9")
If Not Intersect(Cell, Cells.SpecialCells(xlCellTypeAllValidation)) Is Nothing Then
    MsgBox Cell.Address & " contains data validation"
Else
    MsgBox Cell.Addres & " does not contain data validation"
End if 

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-path-analysisInvolves simulating execution paths / interpreting the user code ..to an extent.enhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.feature-inspectionslibrary-specific

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions