|
添加数据有效性- Sub 有效性()
- Dim arr, d As Object, i%, dKeys, str$
- Set d = CreateObject("scripting.dictionary")
- With Sheets("sheet1")
- arr = .Range("a2", .Cells(.Rows.Count, 1).End(3))
- For i = 1 To UBound(arr)
- d(arr(i, 1)) = ""
- d(arr(i, 1) * -1) = ""
- Next
- If d.Count > 1 Then
- dKeys = d.keys
- str = Join(dKeys, ",")
- End If
- With .Range("b2", Cells(Rows.Count, 2)).Validation
- .Delete
- .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=str
- End With
- End With
- End Sub
复制代码 |
|