zoukankan      html  css  js  c++  java
  • EXCEL中同一列避免重复数据[原创]

    宏代码如下:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim i As Long
        If Split(ActiveCell.Address, "$")(2) = 1 Then Exit Sub  '活动单元格是最顶上的单元格时退出SUB
        For i = 1 To (Split(ActiveCell.Address, "$")(2) - 2)
            If Range(Split(ActiveCell.Address, "$")(1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
                Range(Split(ActiveCell.Address, "$")(1) & i).Interior.Color = RGB(200, 160, 35)
                Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
                Dim RC
                RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Split(ActiveCell.Address, "$")(1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理?      ------Powered By 游虫")
                If RC = vbYes Then
                    Range(Split(ActiveCell.Address, "$")(1) & i).Interior.ColorIndex = False
                    Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
                    Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
                    Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Select
                    Exit Sub
                End If
            End If
        Next i
    End Sub

  • 相关阅读:
    swoole推送信息一对一,一对多
    laravel5.8笔记十:Redis操作
    laravel5.8笔记九:数据库曾、更、查、删
    laravel5.8笔记八:数据库(单库和多库)
    laravel5.8笔记七:语言包
    laravel5.8笔记六:公共函数和常量设置
    laravel5.8笔记五:基类控制器和基类模型
    laravel5.8笔记四:中间件
    laravel5.8笔记四:路由
    微软开源自动机器学习工具NNI安装与使用
  • 原文地址:https://www.cnblogs.com/mic86/p/1764948.html
Copyright © 2011-2022 走看看