Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1696|回复: 2

[已解决]VBA代码修改求助

[复制链接]
发表于 2016-4-14 11:59 | 显示全部楼层 |阅读模式
本帖最后由 安全网 于 2016-4-14 22:13 编辑

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim arr, j
    If Target.Count > 1 Then Exit Sub
    w = Target.Row: c = Target.Column: x = Target.Value
    Dim RN As Range
    r = ""
    If (c > 2 And c < 6) Or c = 8 Then
        xstr = Cells(w, 3) & Cells(w, 4) & Cells(w, 5) & Cells(w, 8)
        If Len(x) > 0 Then
            arr = Range("C1:H" & Range("C65536").End(3).Row)
            For i = 3 To UBound(arr)
                If w <> i And arr(i, 1) & arr(i, 2) & arr(i, 3) & arr(i, 6) = xstr Then
                    r = r & "," & i
                    If RN Is Nothing Then Set RN = Range("C" & i & ":H" & i) Else Set RN = Union(RN, Range("C" & i & ":H" & i))
                End If
             Next
            If r <> "" Then
                RN.Borders.Weight = xlMedium
                RN.Interior.ColorIndex = 6
                If MsgBox("当前输入数据与第 " & Mid(r, 2) & " 行相同!是否需要删除?", 4 + 32 + 256) = 6 Then
                    Application.EnableEvents = False
                    Rows(w).ClearContents
                    RN.Interior.ColorIndex = 0
                    RN.Borders.Weight = xlThin
                    Application.EnableEvents = True
                End If
            End If
        End If
    End If

End Sub

Cells(w, 3) & Cells(w, 4) & Cells(w, 5) & Cells(w, 8)这个怎么样设置这4个单元格非空才显示,只要其中一个单元格没有值就不提示
最佳答案
2016-4-14 13:12
没有附件不能测试代码。
发表于 2016-4-14 13:12 | 显示全部楼层    本楼为最佳答案   
没有附件不能测试代码。
回复

使用道具 举报

 楼主| 发表于 2016-4-14 13:36 | 显示全部楼层
蓝桥玄霜 发表于 2016-4-14 13:12
没有附件不能测试代码。

谢谢!问题我已经解决。


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-7 16:19 , Processed in 0.185328 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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