+ Reply to Thread
Results 1 to 5 of 5

Deleting rows that contain string

Hybrid View

dan_za Deleting rows that contain... 03-26-2009, 04:44 AM
arthurbr Re: Deleting rows that... 03-26-2009, 04:57 AM
pboltonchina Re: Deleting rows that... 03-26-2009, 05:16 AM
DonkeyOte Re: Deleting rows that... 03-26-2009, 05:20 AM
dan_za Re: Deleting rows that... 03-26-2009, 05:51 AM
  1. #1
    Registered User
    Join Date
    03-15-2009
    Location
    tellaviv,israel
    MS-Off Ver
    Excel 2007
    Posts
    10

    Deleting rows that contain string

    Hi.
    I need a method that delete rows that contains a string ("class" in my case)
    the problem is that this code is slow. i need to run it on 15 sheets at least.
    Is there a faster way to do this ?
    Thanks
    Here is my code:
    PHP Code: 
    Sub DeleteEmptyRows(wsheet As Worksheet)
        
    Dim calcmode As Long
        Dim ViewMode 
    As Long
        Dim myStrings 
    As Variant
        Dim FoundCell 
    As Range
        Dim I 
    As Long
        Dim myRng 
    As Range
        Dim sh 
    As Worksheet

        With Application
            calcmode 
    = .Calculation
            
    .Calculation xlCalculationManual
            
    .ScreenUpdating False
        End With

      
        With wsheet
        Set myRng 
    = .Range(.Cells(11), .Cells(wsheet.UsedRange.Rows.Count,7))
      
    End With
        
    'Add more search strings if you need
        myStrings = Array("class")
      With myRng
     For I = LBound(myStrings) To UBound(myStrings)
                    Do
                        Set FoundCell = myRng.Find(What:=myStrings(I), _
                                                   After:=.Cells(.Cells.Count), _
                                                   LookIn:=xlFormulas, _
                                                   LookAt:=xlWhole, _
                                                   SearchOrder:=xlByRows, _
                                                   SearchDirection:=xlNext, _
                                                   MatchCase:=False)
                        If FoundCell Is Nothing Then
                            Exit Do
                        Else
                            FoundCell.EntireRow.Delete
                        End If
                    Loop
                Next I
            End With
    End Sub 

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Deleting rows that contain string

    Hi,
    mudraker helped me out with something similar http://www.excelforum.com/excel-prog...ed-values.html

    HTH

  3. #3
    Registered User
    Join Date
    03-26-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Deleting rows that contain string

    I use this, but the information I am looking for is in column H and I want to delete all rows containg KG. You should be able to adapt this to suit.

    HTML Code: 

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Deleting rows that contain string

    Hi Paul - welcome to ExcelForum.com

    I think the question boils down to whether or not the value to be found always resides in one column or in a few specific columns... if so there are other methods even than those listed which would negate the need for iteration altogether... I often prefer to insert temp R1C1 formulae into the last column which in turn permit use of SpecialCells and deletion of all rows simultaneously but if the formulae needs to reference large ranges it may not be viable.

    in short - more info I think... also are you likely to have more than 1 search string (as inferred via your use of Array)

  5. #5
    Registered User
    Join Date
    03-15-2009
    Location
    tellaviv,israel
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Deleting rows that contain string

    Hi all,
    Thanks for the replies, i will be more specific
    I want do delete rows that contains this string..it's not important to me if there are few in the same row.
    I'm not looking on how to do it,i'm looking for the fastest way to do it..
    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1