+ Reply to Thread
Results 1 to 2 of 2

Remove row based on text Criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    06-25-2011
    Location
    Boston
    MS-Off Ver
    Excel 2007
    Posts
    25

    Remove row based on text Criteria

    I have this code that I wrote to remove all rows across all sheets that have the text, actual:, in it but doesn't work. Keep getting the error Next without for, but not sure where exactly to edit it.

    
    Sub Removetextrow()
     
     Dim WS As Worksheet
     Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
       For Each WS In ActiveWorkbook.Worksheets
           With WS
    With WS.UsedRange
    Do
            
    Cells.Find(What:="Actual:", After:=ActiveCell, LookIn:=xlValues, LookAt _
            :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
        Selection.EntireRow.Delete
    Loop
    
       End With
        Next WS
        Application.ScreenUpdating = True
        Application.Calculation = xlCalculationManual
    End Sub
    Any help will be greatly appreciated.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Remove row based on text Criteria

    Hi MZing,

    It looks like you had "With WS" and "With WS.UsedRange", but only one "End With". Try this instead:
    Sub Removetextrow()
    Dim WS As Worksheet
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
       
    For Each WS In ActiveWorkbook.Worksheets
        With WS.UsedRange
            Do
                Cells.Find(What:="Actual:", After:=ActiveCell, LookIn:=xlValues, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False).Activate
                Selection.EntireRow.Delete
            Loop
       End With
    Next WS
    
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationManual
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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