2017-03-01 1 views
5

중복 데이터 (열 "c")가 있고 "D"열의 숫자가있는 행을 삭제하려고합니다. 하지만이 사용하여 코드 메신저입니다 enter image description here조건이있는 전체 중복 행 삭제

사진에서 보이는,하지만 난 "D"에 데이터 행을 삭제하는 방법을 잘 모릅니다으로 홀수 날짜와 중복을 위해 중복

입니다 Set wS = ThisWorkbook.Sheets("Sheet1")에 시트의 이름
Sub del_doops() 
    Dim RowNdx As Long 
    Dim RowNdx2 As Long 

    For RowNdx = Range("A1:f1").End(xlDown).Row To 2 Step -1 
     For RowNdx2 = RowNdx - 1 To 1 Step -1 'Begin at one above RowNdx 

      If Cells(RowNdx, "b").Value = Cells(RowNdx2, "b").Value And _ 
       Cells(RowNdx, "C").Value = Cells(RowNdx2, "C").Value And _ 
       Cells(RowNdx, "E").Value = Cells(RowNdx2, "E").Value And _ 
       Cells(RowNdx, "F").Value <> Cells(RowNdx2, "F").Value Then 
       Rows(RowNdx2).Delete 'this is where i need help 
      End If 

     Next RowNdx2 
    Next RowNdx 

End Sub 
+0

왜 라인 (17) (이다 2 월 20 일이 두 번째 그룹에서 삭제 되었습니까? –

+0

날짜는 변경되지만 신경 쓰지 마세요. R3uK 씨가 절 도와 주셨습니다. 하지만 어쨌든 고마워. –

답변

2

변경 Sheet1는 :

Sub del_doops() 
Dim RowNdx As Long 
Dim RowNdx2 As Long 
Dim wS As Worksheet 

Set wS = ThisWorkbook.Sheets("Sheet1") 
With wS 
    For RowNdx = .Range("A" & .Rows.Count).End(xlUp).Row To 2 Step -1 
     For RowNdx2 = RowNdx - 1 To 1 Step -1 'Begin at one above RowNdx 
      If .Cells(RowNdx, "B").Value = .Cells(RowNdx2, "B").Value And _ 
        .Cells(RowNdx, "C").Value = .Cells(RowNdx2, "C").Value And _ 
        .Cells(RowNdx, "E").Value = .Cells(RowNdx2, "E").Value And _ 
        .Cells(RowNdx, "F").Value <> .Cells(RowNdx2, "F").Value Then 
       If .Cells(RowNdx, "D").Value <> vbNullString Then 
        .Rows(RowNdx).Delete 
       Else 
        If .Cells(RowNdx2, "D").Value = vbNullString Then .Rows(RowNdx2).Delete 
       End If 
      End If 
     Next RowNdx2 
    Next RowNdx 
End With 'wS 
End Sub 
+0

놀라운, 순수한 천재 –

+0

@aj_bk : 다행스럽게 도울 수있어! ;) 그냥 당신을 위해, .Cells (''and'.Range (''With wS' 덕분에) 그리고 당신이 작업하고있는 시트를 적절히 참조하는 가장 쉬운 방법입니다!) – R3uK

+0

좋습니다, 감사합니다. :) –

2
Sub del_doops() 
Dim RowNdx As Long 
Dim RowNdx2 As Long 
For RowNdx = Range("A1:f1").End(xlDown).Row To 2 Step -1 
    For RowNdx2 = RowNdx - 1 To 1 Step -1 'Begin at one above RowNdx 
     If Cells(RowNdx, "B").Value = Cells(RowNdx2, "B").Value And _ 
     Cells(RowNdx, "C").Value = Cells(RowNdx2, "C").Value And _ 
     Cells(RowNdx, "E").Value = Cells(RowNdx2, "E").Value And _ 
     Cells(RowNdx, "F").Value = Cells(RowNdx2, "F").Value Then 
      If Cells(RowNdx, "D").Value = vbNullString And _ 
      Cells(RowNdx2, "D").Value <> vbNullString Then 
       Rows(RowNdx2).Delete 
      Else 
       Rows(RowNdx).Delete 
      End If 
     End If 
    Next RowNdx2 
Next RowNdx 
End Sub