检查重复复制在一个单元格中

我有这个代码来检查重复,如果它发现单元格L中的重复(或更多),是否有可能将K列中的单元格的值复制到一个单元格?

Sub check_duplicates() Dim x As Long Dim LastRow As Long Dim rng As String LastRow = Range("L65536").End(xlUp).Row For x = LastRow To 1 Step -1 If Application.WorksheetFunction.CountIf(Range("L2:L" & x), Range("L" & x).Value) > 1 Then Range("L" & x).Copy End If Next x End Sub 

我希望是你想要做的,让我知道。

在代码之前:

后

 Sub Test() Dim lastrow As Long lastrow = Range("L" & Rows.Count).End(xlUp).Row For i = 2 To lastrow lastrow = Range("L" & Rows.Count).End(xlUp).Row For j = i + 1 To lastrow If Range("L" & j).Value = Range("L" & i).Value Then If Not IsEmpty(Range("K" & i)) Then Range("K" & i) = Range("K" & i) & "," & " " & Range("L" & j) Rows(j).EntireRow.Delete Else Range("K" & i) = Range("L" & j) End If j = j - 1 End If Next j Next i End Sub