vba 判断excel 中数据是否重复 Private Sub CommandButton1_Click() Dim c(256), sum(256), a(256), b(256) As Variant 'c(256),sum(256) 获取单元格的值,a(256),b(256) 设置检查的列和列的字符长度 Dim type1(100) As Variant '保存每一列的类型 Dim area(100, 100) As Variant '保存数值类型的范围 Dim i, j, m, s, y, count1, count, k, strlen As Long 'i,j 用作循环,m,n 用作控制循环,count 记录有几列要检查,count1 有多少行数据 Dim str, strMsg, str1 As String 'str 获取列的字符串,str1 列的长度 strMsg 弹出信息 Dim startValue, endValue As Integer 'startValue 设置范围的默认起始值,endValue 默认终止值 Dim line As Integer '设置从第几行数据开始检查 Dim str2 As String '设置每列的类型 str 字符型,num 数据型,date 日期型 Dim flag As Boolean '是否有重复值的条件,flag=true and s=1 时有重复值 str = "2,3,4" '设置选择的列数 'str1 设置列的最大长度或数值的范围 范围用 num-num 格式 例如 1-2 如果为空则采用设定的默认值 str1 = "" '设置列的数据类型 num 数值型,str 字符型,date 日期型,空为字符型 str2 = "date,str,num" strlen = 10 '设置字符的默认长度 startValue = 1 '设置数值范围的默认起始值 endValue = 100 '设置数值范围的默认终止值 m = InStr(1, str, ",") n = InStr(1, str1, ",") l = InStr(1, str2, ",") i = 1 line = 1 '设置从第一行数据开始检查 Do While 1 = 1 If Cells(i, 1) = "" And Cells(i, 2) = "" And Cells(i + 1, 1) = "" And Cells(i + 1, 2) = "" Then Exit Do Else count1 = count1 + 1 '计算有多少行数据 End If i = i + 1 Loop i = 0 While m > 0 a(i) = Left(str, m - 1) + 0 '获取所设置的列 If l = 0 Then type1(i) = "str" Else type1(i) = Left(str2, l - 1) End If If UCase(type1(i)) = "STR" Then '如果是字符型 If n = 0 Then b(i) = Left(str1, n) '获取所设置的列的长度 Else b(i) = Left(str1, n - 1) End If If b(i) = "" Then b(i) = strlen End If Else If UCase(type1(i)) = "NUM" ...