Consulting

Results 1 to 5 of 5

Thread: How to Delete Visible Rows in VBA?

  1. #1

    How to Delete Visible Rows in VBA?

    I'm just wondering what's wrong with my code?

    The line:
    Range("A1:H999000").AutoFilter Field:=4, Criteria1:="-100"
    is okay, but I'm having problem with the second line.

    Thanks!

    [VBA]Sub Filter()
    With ActiveSheet
    Range("A1:H999000").AutoFilter Field:=4, Criteria1:="-100"
    Columns("A").SpecialCells(xlCellTypeVisible).EntireRow.Delete
    End With

    End Sub
    [/VBA]

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Try Range("A:A")

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub Filter()
    Dim rng As Range
    Dim LastRow As Long

    With ActiveSheet
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    Set rng = .Range("A1:H" & LastRow)
    rng.AutoFilter Field:=4, Criteria1:="-100"
    Set rng = rng.Columns("A").SpecialCells(xlCellTypeVisible)
    If Not rng Is Nothing Then rng.EntireRow.Delete
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    I'm still having trouble with:

    Columns("A").SpecialCells(xlCellTypeVisible)

    I tried doing it manually though(select rows, then F5 visible cells only), but it gives me this error message(pls see attch image).
    Last edited by genracela; 07-04-2010 at 06:16 PM.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can you post the workbook?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •