Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
楼主: 安全网

[已解决]求助禁止录入重复数据的VBA代码

[复制链接]
发表于 2016-1-7 09:04 | 显示全部楼层

Range("C2:H" & I).Interior.ColorIndex = 0
改成
Range("C" & I & ":H" & I).Interior.ColorIndex =0
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
回复

使用道具 举报

 楼主| 发表于 2016-1-7 09:18 | 显示全部楼层
zjdh 发表于 2016-1-7 09:04

Range("C2:H" & I).Interior.ColorIndex = 0
改成

谢谢!我自己也就是这样弄好了!


回复

使用道具 举报

 楼主| 发表于 2016-1-7 10:11 | 显示全部楼层
zjdh 发表于 2016-1-7 09:04

Range("C2:H" & I).Interior.ColorIndex = 0
改成

能否给重复的数据加上边框和字体变粗
QQ图片20160107100403.png
回复

使用道具 举报

发表于 2016-1-7 10:19 | 显示全部楼层
自己录制一个宏,把相关语句放进去。
回复

使用道具 举报

 楼主| 发表于 2016-1-7 10:22 | 显示全部楼层
zjdh 发表于 2016-1-7 10:19
自己录制一个宏,把相关语句放进去。

这样的没有录制过不知道怎么写
回复

使用道具 举报

发表于 2016-1-7 10:41 | 显示全部楼层
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column > 2 And Target.Column < 9 Then
        W = Target.Row
        If Len(Cells(W, 3)) * Len(Cells(W, 4)) * Len(Cells(W, 5)) * Len(Cells(W, 8)) <> 0 And Target.Count = 1 Then
            Application.EnableEvents = False
            ARR = Range("C1:H" & Range("C65536").End(3).Row - 1)
            For I = 1 To UBound(ARR)
                If ARR(I, 1) = Cells(W, 3) And ARR(I, 2) = Cells(W, 4) And ARR(I, 3) = Cells(W, 5) And ARR(I, 6) = Cells(W, 8) Then
                    With Range("C" & I & ":H" & I)
                        .Font.FontStyle = "加粗"
                        .Borders(xlEdgeLeft).Weight = xlMedium
                        .Borders(xlEdgeTop).Weight = xlMedium
                        .Borders(xlEdgeBottom).Weight = xlMedium
                        .Borders(xlEdgeRight).Weight = xlMedium
                        .Interior.ColorIndex = 6
                    End With

                    If MsgBox("输入数据与第 " & I & " 行相同!是否需要删除?", 4 + 32 + 256) = 6 Then
                        Rows(W).Delete
                        Range("C2:H" & I).Interior.ColorIndex = 0
                    End If
                End If
            Next
            Application.EnableEvents = True
        End If
    End If
End Sub
回复

使用道具 举报

 楼主| 发表于 2016-1-7 11:23 | 显示全部楼层
zjdh 发表于 2016-1-7 10:41
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column > 2 And Target.Column < 9  ...

这样的如果删掉了重复的,前面几个填充的颜色只能取消一行填充,是什么原因不能全部取消了


回复

使用道具 举报

发表于 2016-1-7 12:51 | 显示全部楼层
不是你要求的吗??
回复

使用道具 举报

 楼主| 发表于 2016-1-7 13:42 | 显示全部楼层
zjdh 发表于 2016-1-7 12:51
不是你要求的吗??

那怎么样在删除了新录入的数据后,取消所有重复数据的填充颜色
回复

使用道具 举报

发表于 2016-1-7 14:29 | 显示全部楼层
我原来的宏不就是吗??
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-5 09:54 , Processed in 0.283742 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表