2017-09-28 1 views
1

데이터가 있으며 일부 필터링을 수행했습니다. 지금은 전체 행을 마지막으로 표시된 행까지 삭제하려고합니다. 또한,이 경우 머리글 (행 5)을 포함하고 싶지 않습니다. 당신은 단지 당신이있는 경우 가시 행을 삭제하려면 필터링 된 데이터를 선택하고 머리글을 제외한 마지막 행으로 삭제

Dim lr As Long 
lr = Cells(Rows.Count, 1).End(xlUp).Row 
Range("A6:A" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Delete 

이 시도 ...

Dim row1 As Variant 
row1 = Rows(5).Offset(1, 0) 
lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row 
Rows("row1:" & lastrow).SpecialCells(xlCellTypeVisible).EntireRow.Delete 
+1

것은' "ROW1을"교체'ROW1 &'와 ":"' –

답변

0

.

Sub DeleteVisibleRows() 
    With ActiveSheet 
     On Error Resume Next 
     .Range("A5", .Range("A" & .Rows.Count).End(xlUp)).Offset(1).EntireRow _ 
     .SpecialCells(xlCellTypeVisible).Delete 
     On Error GoTo 0 
    End With 
End Sub 
+0

내가 왜 코드에 대한 오류 처리기의 필요성 감사 Btw는 이해할 수있다 –

+0

'은'아무튼 경우 SpecialCells' 오류가 발생합니다?! 모든 세포를 찾는다. –

0

이 시도주십시오 : 나는 아래의 코드를 해결할 방법을 잘 모르겠습니다 데이터 세트에 필터를 적용했습니다.

Dim lr As Long 
lr = Cells(Rows.Count, 1).End(xlUp).Row 
If ActiveSheet.FilterMode Then 
    On Error Resume Next 
    Range("A6:A" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Delete 
End If 
0

아래 시도하십시오 : SpecialCells 작업을 할 때마다 당신은 오류 처리기를 추가 할 필요가

Sub test() 

    Dim lastrow As Long 
    Dim rng As Range 

    lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row 

    Set rng = Rows("6:" & lastrow) 

    rng.Delete Shift:=xlUp 

    End Sub 
관련 문제