+ Reply to Thread
Results 1 to 6 of 6

Macro to delete rows based on partial text

  1. #1
    Registered User
    Join Date
    12-16-2008
    Location
    Blackpool, UK
    MS-Off Ver
    2003, 2007, 2010
    Posts
    54

    Macro to delete rows based on partial text

    Hi all,

    I am looking for a macro to delete entire rows based on the a partial text contained in column A.

    For example, I have a list of names that I need to keep but I need to delete the rows in which column A contain cells starting with the following.

    BOOKLET 201, PROMO
    LOTTO, PRIZE 2
    PBT 2, STW WEEK 4

    the numbrs in these cells increment therefore I can not make it a specific to the cell but need to select based on Booklet, Lotto and PBT.

    I am a novice at VBA and any help would be apreciated Thanks.
    Last edited by rossi_69; 04-09-2009 at 06:28 PM. Reason: Sloved

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro to delete rows based on partial text

    Hi

    You may want to change the finishing row but try

    Please Login or Register  to view this content.
    rylo

  3. #3
    Registered User
    Join Date
    12-16-2008
    Location
    Blackpool, UK
    MS-Off Ver
    2003, 2007, 2010
    Posts
    54

    Re: Macro to delete rows based on partial text

    Rylo thanks for the reply,

    I ran the code as below and could not get any results,

    PHP Code: 
    Sub Delete_rows()

    For 
    Cells(Rows.Count1).End(xlUp).Row To 1 Step -1
      
        
    If Left(Cells(i1), 7) = "Booklet" Or Left(Cells(i1), 5) = "Lotto" Or Left(Cells(i1), 3) = "PBT" Then
          Cells
    (i1).EntireRow.Delete
        End 
    If
      
      
    Next i

    End Sub 
    any ideas, I attached an example of some of the spreadsheet to help.

    Thanks again.
    Rossi
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Macro to delete rows based on partial text

    Your macro has "Booket", but Column A contains "BOOKLET"
    change the line to:


    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro to delete rows based on partial text

    rossi

    Yep foxguy is right about the case sensitivity. I just grabbed your comment
    need to select based on Booklet, Lotto and PBT
    and based the selection on that.


    rylo

  6. #6
    Registered User
    Join Date
    12-16-2008
    Location
    Blackpool, UK
    MS-Off Ver
    2003, 2007, 2010
    Posts
    54

    Re: Macro to delete rows based on partial text

    Thanks guys,

    I discovered that this macro takes ages so i modified it with the following code to make it quicker and turned off redrawing.

    PHP Code: 
    Sub Delete_rows_CTD_SLOTS()

    With Application

            
    .Calculation xlCalculationManual

            
    .ScreenUpdating False

    For Cells(Rows.Count1).End(xlUp).Row To 1 Step -1
      
        
    If Left(Cells(i1), 7) = "BOOKLET" Or Left(Cells(i1), 10) = "TOURNAMENT" Or Left(Cells(i1), 5) = "LOTTO" Or Left(Cells(i1), 3) = "PBT" Or Left(Cells(i1), 4) = "SEAT" Or Left(Cells(i1), 5) = "PRIZE" Or Left(Cells(i1), 4) = "BOOK" Or Left(Cells(i1), 6) = "PLAYER" Then
          Cells
    (i1).EntireRow.Delete
        End 
    If
      
      
    Next i
      
            
    .Calculation xlCalculationAutomatic

            
    .ScreenUpdating True

        End With

    End Sub 
    Works like a charm now.

+ 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