2017-12-07 37 views
0
Dim rng3 As Range 

    Set rng3 = Range("J1").CurrentRegion 

    rng3.AutoFilter Field:=10, Criteria1:="<>", Operator:=xlFilterValues 

    With rng3 
     With .Offset(1).Resize(.Rows.Count - 1) 
      Application.DisplayAlerts = False 
      .Rows.Delete 
      Application.DisplayAlerts = True 
     End With 
    End With 

위 (이론) 코드 필터를 삭제하고 결과를 삭제 . 문제는 J 열에 이미 빈 데이터 만 있으면 모든 것을 삭제하는 것입니다.공식, 모든을 ("<>") 빈 이외 "J1"아무것도에

+0

'.SpecialCells (xlCellTypeVisible)' –

답변

2

난 그냥 시도하고 다음 테스트는 예상대로 수행했습니다

Sub foo() 
    Set rng3 = Range("J1").CurrentRegion 
    rng3.AutoFilter Field:=10, Criteria1:="<>", Operator:=xlFilterValues 

    With rng3.SpecialCells(xlCellTypeVisible) 
      Application.DisplayAlerts = False 
      NewAddress = Replace(rng3.Rows.Name, "A$1", "A$2") 
      Range(NewAddress).Delete 
      Application.DisplayAlerts = True 
    End With 
End Sub 

또는 다른 접근 방식 사용 :

Sub foo2() 
LastRow = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row 'Find the last row with data on Column A 

For i = 2 To LastRow 'Loop from Row 2 to the Last Row with data 
    If Sheet1.Cells(i, 10).Value <> "" Then Sheet1.Rows(i).Delete 'Check Column J for any value, and if it has a value delete that row 
Next i 
End Sub 
+0

좋은 자리를! 'specialcells'이 사용되지 않았다는 것을보고 난 후에 계속 읽지 않았습니다. –

+0

크기 조정 코드를 제외 시켰을 때의 문제는 이상한 것이 아닌 헤더가 삭제되는 것입니다. –

+0

@ K.Robert 내 대답이 업데이트되었습니다. 첫 번째 행을 제외하려면 약간의 해결 방법이 있습니다.이 작업을 수행하는 더 좋은 방법이있을 것이라고 확신하지만, 지금은 원하는 작업을 수행 할 것입니다. – Xabier