열의 중복 값을 기반으로 Excel에서 행을 삭제하려고합니다. 예를 들어,열의 중복을 기반으로 Excel에서 행을 삭제합니다.
열 B
에는 중복 값이 있습니다. 중복 제거 기능만으로는 도움이되지 않습니다.
열의 중복 값을 기반으로 Excel에서 행을 삭제하려고합니다. 예를 들어,열의 중복을 기반으로 Excel에서 행을 삭제합니다.
열 B
에는 중복 값이 있습니다. 중복 제거 기능만으로는 도움이되지 않습니다.
글쎄,이 코드는 완벽 어쩌면
ActiveSheet.Range("$A$1:$B$4").RemoveDuplicates Columns:=Array(1, 2), Header:=xlNo
없는 가장 최적화 된 솔루션 작동하지만, 작업을
Public Sub DeleteDuplicates()
Dim rng As Range, cell As Range, find As Range, previous As Range
Set rng = Worksheets("Test").Range("A:A")
' For each cell of the column
For Each cell In rng
' Check duplicates only if the cell is not empty
If Trim(cell) <> "" Then
' Search for the same value in column A
Set find = rng.find(What:=cell, After:=cell, LookAt:=xlWhole, MatchCase:=True)
' if a result is found
If Not find Is Nothing Then
Do
Set previous = Nothing
' If the column B is the same, save the row as "to be deleted"
' The delete is not now otherwise the FindNext won't work
If find.Offset(, 1) = cell.Offset(, 1) Then
Set previous = find
End If
Set find = rng.FindNext(find)
' If a duplicate was found, delete the raw
If Not previous Is Nothing Then
previous.EntireRow.Delete
End If
' if no more duplicate, exit the do loop
If find Is Nothing Then
Exit Do
End If
' if address of the result is the same as the clel, exit the do loop
If cell.Address = find.Address Then
Exit Do
End If
Loop While True
End If
End If
Next
End Sub
안녕하세요. 오류 91이 발생합니다. –
을 수행하지만,이 모든 열을 선택합니다. 하나의 열을 기준으로 복제본을 삭제하고 싶습니다. –
[column_number] 대신 컬럼을 설정하고 [data_range] 대신 테이블 범위'ActiveSheet.Range ([data_range])를 설정하십시오. RemoveDuplicates Columns : = [ column_number], 헤더 : = xlNo' – lancer102rus
아니요, 작동하지 않는 것 같습니다. 그것의 모든 변형을 시도 –