Description
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:
-
The range object is a single cell, or refers to an address that resolves to a single cell, or;
-
A Range is
Intersect
ed 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