Consulting

Results 1 to 2 of 2

Thread: VBA Code to Delete Rows with AWR

  1. #1

    VBA Code to Delete Rows with AWR

    Hi,

    In an Excel Spreadsheet I want to do a macro that will delete all rows that contain AWR in Column J.

    Do I have to do some sort of loop that will start at the top (or bottom row), check to see if AWR is present and if so delete that row and then move onto the next row until the end of the data is reached.

    Or is there an easier way to do the same thing?

    Cheers,

    Bren.

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

    Dim Lastrow As Long
    Dim rng As Range

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, "J").End(xlUp).Row
    Set rng = .Range("J1").Resize(Lastrow)
    rng.AutoFilter field:=1, Criteria1:="AWR"
    Set rng = rng.Offset(1, 0)
    On Error Resume Next
    Set rng = rng.SpecialCells(xlCellTypeVisible)
    On Error GoTo 0

    If Not rng Is Nothing Then

    rng.EntireRow.Delete
    End If

    .Range("A1").AutoFilter
    End With
    [/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

Posting Permissions

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