码迷,mamicode.com
首页 > 数据库 > 详细

自动生成一列不重复数据库

时间:2018-12-13 17:49:54      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:validate   cells   val   nbsp   count   row   sele   select   span   

Private Sub Worksheet_Activate()

Dim d As Object
Dim arr
Dim x As Integer
Set d = CreateObject("scripting.dictionary")
arr = Sheet1.Range("a2:a" & Sheet1.Cells(Rows.Count, 1).End(xlUp).Row)
For x = 1 To UBound(arr)
d(arr(x, 1)) = ""
Next
Sheets("Sheet2").Select
    Range("C2").Select
    
    With Selection.Validation
        .Delete
        
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(d.keys, ",")
        .Add 3, 1, 1, Join(d.keys, ",")
       
    End With
   


End Sub

 



自动生成一列不重复数据库

标签:validate   cells   val   nbsp   count   row   sele   select   span   

原文地址:https://www.cnblogs.com/wangzj12/p/10115216.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!