2016-07-12 3 views

답변

0

글쎄,이 코드는 완벽 어쩌면

ActiveSheet.Range("$A$1:$B$4").RemoveDuplicates Columns:=Array(1, 2), Header:=xlNo 
+0

을 수행하지만,이 모든 열을 선택합니다. 하나의 열을 기준으로 복제본을 삭제하고 싶습니다. –

+0

[column_number] 대신 컬럼을 설정하고 [data_range] 대신 테이블 범위'ActiveSheet.Range ([data_range])를 설정하십시오. RemoveDuplicates Columns : = [ column_number], 헤더 : = xlNo' – lancer102rus

+0

아니요, 작동하지 않는 것 같습니다. 그것의 모든 변형을 시도 –

0

없는 가장 최적화 된 솔루션 작동하지만, 작업을

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 
+0

안녕하세요. 오류 91이 발생합니다. –

관련 문제