2013-10-07 3 views
0

sheet2의 열 A와 함께 sheet1의 열 L에 일치하는 것을 기반으로 Excel에서 CSV 파일 내의 여러 행을 제거해야합니다. 내용은 이메일 주소입니다. 이것을 어떻게 할 수 있습니까?일치 항목을 기반으로 전체 행을 제거 하시겠습니까?

따라서 sheet2 열 A에 sheet1 - Column L에있는 전자 메일 주소 중 하나와 일치하는 전자 메일 주소가 있으면 해당 전자 메일 주소가있는 sheet1에서 전체 행을 제거해야합니다.

Sheet1의 아래 아래 Sheet1

시트 2 : 이 Error with mehow's code

+0

음, 자동 필터를 사용할 수 있습니까? –

+0

자동 필터 사용 방법? –

+0

자동 필터 예제 [여기]를 볼 수 있습니다 (http://stackoverflow.com/questions/11631363/how-to-copy-a-line-in-excel-using-a-specific-word-and-pasting-to -another-excel-s) –

답변

1

이 작동합니다 아주 : 나는 모듈로 코드를 실행할 때 Sheet2

@mehow, 여기에 내가 얻을 이미지의 어떤 루프도 포함하지 않으므로 원하는 작업을 빠르게 수행 할 수 있습니다.

Sub DeleteDuplicates() 

Dim StartingScreenUpdateValue As Boolean 
Dim StartingEventsValue As Boolean 
Dim StartingCalculations As XlCalculation 

With Application 
    StartingScreenUpdateValue = .ScreenUpdating 
    StartingEventsValue = .EnableEvents 
    StartingCalculations = .Calculation 
    .ScreenUpdating = False 
    .EnableEvents = False 
    .Calculation = xlCalculationManual 
End With 


Dim varTestValues As Variant 
Dim sh1 As Worksheet 
Dim sh2 As Worksheet 

Set sh1 = Sheets("Sheet1") 
Set sh2 = Sheets("Sheet2") 

With sh2 
    varTestValues = .Range("A1", .Range("A" & .Rows.Count).End(xlUp)) 
End With 

sh1.Range("L1", sh1.Range("L" & sh1.Rows.Count).End(xlUp)) _ 
    .AutoFilter Field:=12, Criteria1:=Application.Transpose(varTestValues), Operator:=xlFilterValues 

sh1.Range("L2", sh1.Range("L" & sh1.Rows.Count).End(xlUp)) _ 
    .SpecialCells(xlCellTypeVisible).EntireRow.Delete 

sh1.AutoFilterMode = False 

With Application 
    .ScreenUpdating = StartingScreenUpdateValue 
    .EnableEvents = StartingEventsValue 
    .Calculation = StartingCalculations 
End With 

End Sub 

참고 :이 알려 주시기 바랍니다하지 않는 경우이 코드는 데이터를 가정 실행됩니다이 헤더를 가지고있다.

하는 것은 100 % 작동하는지 당신이 확신 할 때까지가 항상 실제 데이터를 데이터의 사본에 코드를 실행하지 기억.

+0

어디에 넣어야합니까? 그래, 나는 첫 번째 행을 차지하는 두 시트에 헤더가 있습니다. –

+0

매크로로 추가하고 실행했습니다. 그러면 sheet1의 모든 내용이 제거되고 sheet2는 동일하게 유지됩니다. –

+0

오류가 발생했습니다. 방법 : 개체 범위의 자동 필터가 실패했습니다. –