Consulting

Results 1 to 8 of 8

Thread: Solved: Deleting Unwanted Rows

  1. #1

    Solved: Deleting Unwanted Rows

    Hi all

    I am using the following VAB Code to check and delete unwanted Rows. But the data I have is about 30,000-40,000 lines, and it takes a long time to run. Is there a quicker way?????

    [vba] Do While (Cells(Row, 1).Value <> "")
    If Left(Cells(Row, 1), 8) = "List all" Then
    Cells(Row, 1).Select
    Selection.EntireRow.Delete
    ElseIf Cells(Row, 1) = "RSOBranchName" Then
    Cells(Row, 1).Select
    Selection.EntireRow.Delete
    ElseIf Cells(Row, 7) <> "Overdue" Then
    Cells(Row, 1).Select
    Selection.EntireRow.Delete
    Else
    Row = Row + 1
    End If
    Loop
    [/vba]

    Thanx in Advance
    Grant

  2. #2
    VBAX Regular
    Joined
    Jan 2006
    Posts
    28
    Location

    Smile

    Good morning Caddyman
    Quote Originally Posted by Caddyman
    But the data I have is about 30,000-40,000 lines, and it takes a long time to run. Is there a quicker way?????
    You will find that more often than not you don't have to select an object to do something with it. Selecting each row before you delete it just takes up necessary time. You can also turn off the screenupdating, which will also speed the macro up - have a look at the amendments I've made below :
    [vba]Application.ScreenUpdating = False
    Do While (Cells(Row, 1).Value <> "")
    If Left(Cells(Row, 1), 8) = "List all" Then
    Cells(Row, 1).EntireRow.Delete
    ElseIf Cells(Row, 1) = "RSOBranchName" Then
    Cells(Row, 1).EntireRow.Delete
    ElseIf Cells(Row, 7) <> "Overdue" Then
    Cells(Row, 1).EntireRow.Delete
    Else
    Row = Row + 1
    End If
    Loop
    Application.ScreenUpdating = True[/vba]
    HTH

    DominicB

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    DominicB wouldn't this kind of method be quicker?
    [vba]
    Dim Rng As Range
    Set Rng = Range("A2:J" & Range("J" & Rows.Count).End(xlUp).Row)
    Columns("A:A").AutoFilter Field:=1, Criteria1:="RSOBranchName"
    Rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete Shift:=xlUp
    ActiveSheet.AutoFilterMode = False
    [/vba]of course for the criteria you could use an array of variants.
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Simon,

    What is the purpose of that Selection.Delete at the end?
    ____________________________________________
    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

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    An oversite on my behalf i've fixed it now......flippin' 'eck we will have to rename you to " Old Eagle Eye"
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Well Zack said I had to do my share of the site admin even if it isn't official <g>
    ____________________________________________
    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

  7. #7
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by xld
    Well Zack said I had to do my share of the site admin even if it isn't official <g>
    YES! VINDICATION!!!

  8. #8
    Thanx All

    Dominic's code I understand, , Simon's, well I have never really used ranges to much . I think I shall do some reading on ranges very soon......

    Guess that shows how much of a rookie at VBA I really am.

Posting Permissions

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