Excel精英培训网

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

[VBA] VBA每一行分解再组合最后去除相同项

[复制链接]
发表于 2016-9-30 09:21 | 显示全部楼层 |阅读模式
VBA每一行分解再组合最后去除相同项

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-9-30 14:30 | 显示全部楼层
看看

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1 +3 收起 理由
laoau138 + 3 来学习

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2016-9-30 17:26 | 显示全部楼层

果然是高手


Sub Combine()
Application.ScreenUpdating = False
With Sheet1
    If .Range("I9999").End(xlUp).Row > 11 Then .Range(.Cells(11, 9), .Cells(.Range("i99999").End(xlUp).Row, 12)).ClearContents
    n = 11
    For i = 11 To .Range("A9999").End(xlUp).Row
        For j1 = 1 To 3
            For j2 = j1 + 1 To 4
                For j3 = j2 + 1 To 5
                    For j4 = j3 + 1 To 6
                        .Cells(n, 9) = .Cells(i, j1)
                        .Cells(n, 10) = .Cells(i, j2)
                        .Cells(n, 11) = .Cells(i, j3)
                        .Cells(n, 12) = .Cells(i, j4)
                        n = n + 1
                    Next
                Next
            Next
        Next
    Next
End With
Application.ScreenUpdating = True
End Sub

Sub Del_Same()
Application.ScreenUpdating = False
With Sheet1
    If .Range("N9999").End(xlUp).Row > 11 Then .Range(.Cells(11, 14), .Cells(.Range("N99999").End(xlUp).Row, 17)).ClearContents

    .Range(.Cells(11, 14), .Cells(11, 17)).Value = .Range(.Cells(11, 9), .Cells(11, 12)).Value

    n = 12
    For i = 12 To .Range("I99999").End(xlUp).Row
        m = 0
        For j = 11 To n
            If (.Cells(j, 14) = .Cells(i, 9)) And (.Cells(j, 15) = .Cells(i, 10)) And (.Cells(j, 16) = .Cells(i, 11)) And (.Cells(j, 17) = .Cells(i, 12)) Then m = 1
        Next
        If m = 0 Then
            .Range(.Cells(n, 14), .Cells(n, 17)).Value = .Range(.Cells(i, 9), .Cells(i, 12)).Value
            n = n + 1
        End If
    Next
End With
Application.ScreenUpdating = True
End Sub



回复

使用道具 举报

 楼主| 发表于 2016-9-30 17:30 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-26 06:04 , Processed in 8.536926 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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