Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
12
返回列表 发新帖
楼主: huangkepan

大侠们,帮忙写个删除重复项的程序呗

[复制链接]
发表于 2019-7-15 16:40 | 显示全部楼层
Sub TQ()
    Dim X%, K%
    Dim str As String
    K = 1
    For X = 2 To Sheet1.Cells(Rows.Count, 2).End(xlUp).Row
        If Application.WorksheetFunction.CountIf(Sheet1.Range("B2:B" & X), Sheet1.Cells(X, 2)) = 1 Then
            K = K + 1
            Sheet1.Cells(X, 2).Copy Sheet2.Cells(K, 1)
        ElseIf Application.WorksheetFunction.CountIf(Sheet1.Range("B2:B" & X), Sheet1.Cells(X, 2)) = 2 Then
            str = str & Cells(X, 2).Value & ","
        End If
    Next X
    Sheet2.Range("A1") = str
End Sub
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
回复

使用道具 举报

发表于 2019-7-15 16:43 | 显示全部楼层
Sub TQ()
    Dim X%, K%
    Dim str As String
    K = 1
    With Sheet1
    For X = 2 To Sheet1.Cells(Rows.Count, 2).End(xlUp).Row
        If Application.WorksheetFunction.CountIf(.Range("B2:B" & X), .Cells(X, 2)) = 1 Then
            K = K + 1
            .Cells(X, 2).Copy Sheet2.Cells(K, 1)
        ElseIf Application.WorksheetFunction.CountIf(.Range("B2:B" & X), .Cells(X, 2)) = 2 Then
            str = str & Cells(X, 2).Value & ","
        End If
    Next X
    End With
    Sheet2.Range("A1") = str
End Sub

评分

参与人数 1学分 +2 收起 理由
huangkepan + 2

查看全部评分

回复

使用道具 举报

发表于 2019-7-15 16:45 | 显示全部楼层
请试下!!!

删除重复.rar

19.4 KB, 下载次数: 4

评分

参与人数 1学分 +2 收起 理由
huangkepan + 2

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 13:39 , Processed in 0.246250 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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