zoukankan      html  css  js  c++  java
  • Excel中删除两列中重复的数据[原创]

    宏代码如下 :

    Sub DelTheSame()
        Dim MyColCompare
    InPutCel:
        MyColCompare = Application.InputBox(Prompt:="请输入需要对比的两列,用英文逗号隔开(,)!" & vbCrLf & vbCrLf & "例如:A,C", Default:="A,B", Title:="请输入需要对比的列", Type:=2 + 4)
        If MyColCompare = False Then Exit Sub Else MyColCompare = Replace(MyColCompare, " ", "")
        Dim SubCel() As String
        SubCel() = Split(MyColCompare, ",")
        If UBound(SubCel()) <> 1 Or Replace(MyColCompare, ",", "") = "" Then MsgBox "请输入两个列号,用英文逗号隔开,如:A,C", vbOKOnly + vbExclamation, "提示!": GoTo InPutCel
        If Len(SubCel(0)) <> 1 Or Len(SubCel(1)) <> 1 Then MsgBox "本程序只能对比 A-Z 之间的列,请重新输入,如:A,C", vbOKOnly + vbExclamation, "提示!": GoTo InPutCel
        If Not ((Asc(SubCel(0)) >= 65 And Asc(SubCel(0)) <= 90) Or (Asc(SubCel(0)) >= 97 And Asc(SubCel(0)) <= 122)) Or Not ((Asc(SubCel(1)) >= 65 And Asc(SubCel(1)) <= 90) Or (Asc(SubCel(1)) >= 97 And Asc(SubCel(1)) <= 122)) Then
            MsgBox "本程序只能处理A-Z之间的列,请重新输入,如:A,C", vbOKOnly + vbExclamation, "提示!"
            GoTo InPutCel
        End If
    BeginCheck:
        Range(SubCel(0) & 1).Select
        For i = 1 To ActiveSheet.Range(SubCel(0) & "65535").End(xlUp).Row
            Range(SubCel(0) & i).Select
            For j = 1 To ActiveSheet.Range(SubCel(1) & "65535").End(xlUp).Row
                If Range(SubCel(0) & i).Value = Range(SubCel(1) & j).Value And (Range(SubCel(0) & i).Value <> "" Or Range(SubCel(1) & j).Value <> "") Then
                    Range(SubCel(0) & i).Delete shift:=xlUp
                    Range(SubCel(1) & j).Delete shift:=xlUp
                    GoTo BeginCheck
                'Else
                '    Range(SubCel(0) & i).Interior.Color = RGB(200, 160, 35)
                End If
            Next j
        Next i
    End Sub

  • 相关阅读:
    [视频监控]用状态机图展示Layout切换关系
    初次打开mysql5.6后
    eclipse 项目乱码
    java servlet 中遇到的编码问题
    解决HttpServletResponse输出的中文乱码问题
    The first day of my Blog
    最大子段和
    LOI 54 成立一周年纪(zuo)念(si)
    水题 逆序对 NOIP 2013 火柴排队
    搜索 由浅入深 之一 水题
  • 原文地址:https://www.cnblogs.com/mic86/p/1764944.html
Copyright © 2011-2022 走看看