Can I use VBA function to return a (dynamic) list of acceptable values into Excel's data validation?

后端 未结 6 1547
夕颜
夕颜 2020-12-19 11:28

For a given cell, I select Data/Validation and set Allow to \"List\". I now wish to set Source like so:

=rNames(REGS)

but that does not work (name not found

6条回答
  •  臣服心动
    2020-12-19 12:17

    For the future:

    Following is then used in a named range and the named range set as the 'Data Validation' 'List' value

    Function uniqueList(R_NonUnique As Range) As Variant
    
        Dim R_TempList As Range
        Dim V_Iterator As Variant
        Dim C_UniqueItems As New Collection
    
        On Error Resume Next
        For Each V_Iterator In R_NonUnique
            C_UniqueItems.Add "'" & V_Iterator.Parent.Name & "'!" & V_Iterator.Address, CStr(V_Iterator.Value2)
        Next V_Iterator
        On Error GoTo 0
    
        For Each V_Iterator In C_UniqueItems
            If R_TempList Is Nothing Then
                Set R_TempList = Range(V_Iterator)
            End If
            Set R_TempList = Union(R_TempList, Range(V_Iterator))
        Next V_Iterator
    
        Set uniqueList = R_TempList
    
    End Function
    

提交回复
热议问题