VBA 用于从重复单元格复制和粘贴单元格的宏

VBA Macro for copy and pasting cells from duplicate cells

我有一个数据集如下:

本质上,我需要删除一个重复的行(禁止项目)并将项目移到第一行和另一行的右侧。

示例

我对 VBA 的经验很少,如果能提供有关从哪里开始的帮助,我们将不胜感激。

这应该是直截了当的,任何问题都可以问

Public Sub MergeProjects()
Dim lastrow As Long
Dim lastcol As Long
Dim i As Long

    Application.ScreenUpdating = False

    With ActiveSheet

        lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
        For i = lastrow - 1 To 2 Step -1

            If .Cells(i + 1, "A").Value = .Cells(i, "A").Value And _
                .Cells(i + 1, "B").Value = .Cells(i, "B").Value And _
                .Cells(i + 1, "C").Value = .Cells(i, "C").Value And _
                .Cells(i + 1, "D").Value = .Cells(i, "D").Value And _
                .Cells(i + 1, "E").Value = .Cells(i, "E").Value Then

                lastcol = .Cells(i, "A").End(xlToRight).Column
                .Cells(i + 1, "F").Resize(, 100).Copy .Cells(i, lastcol + 1)
                .Rows(i + 1).Delete
            End If
        Next i

        lastcol = .Range("A1").CurrentRegion.Columns.Count
        .Range("F1:G1").Value = Array("Project 1", "Project 2")
        If lastcol > 7 Then

            .Range("F1:G1").AutoFill .Range("F1").Resize(, lastcol - 5)
        End If
    End With

    Application.ScreenUpdating = True
End Sub