Determine if cell contains data validation

后端 未结 7 1386
盖世英雄少女心
盖世英雄少女心 2020-11-28 15:40

I am writing a VBA code that goes through a range of cells checking if each cell has data validation (drop down menu) and if not assign one to it from a list on another shee

相关标签:
7条回答
  • 2020-11-28 16:42

    I know this question is old, but since it comes up when Googling "excel vba check if cell has validation", I figured I would add my grain of salt.

    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.

    Hence, here is a more efficient way to check if a single cell has validation:

    Function HasValidation(cell As Range) As Boolean
        Dim t: t = Null
    
        On Error Resume Next
        t = cell.Validation.Type
        On Error GoTo 0
    
        HasValidation = Not IsNull(t)
    End Function
    
    0 讨论(0)
提交回复
热议问题