Do Until Loop, Loop help please

NewUser2

Board Regular
Joined
Jan 27, 2015
Messages
54
I am trying to run a ‘Do Until’ loop in my macro that will search for a word, if its found, select the whole row containing that word, delete it, find the next and repeat. So far I have:</SPAN></SPAN>

Do</SPAN></SPAN>
Cells.Find(What:="Find_Word", After:=ActiveCell, LookIn:=xlFormulas, _</SPAN></SPAN>
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _</SPAN></SPAN>
MatchCase:=False, SearchFormat:=False).Activate</SPAN></SPAN>
ActiveCell.Rows("1:1").EntireRow.Select</SPAN></SPAN>
ActiveCell.Activate</SPAN></SPAN>
Selection.Delete Shift:=xlUp</SPAN></SPAN>
ActiveCell.Offset(-1, 0).Select</SPAN></SPAN>
Loop</SPAN></SPAN>

It deletes the rows I want, but just gives me a ‘Run-time error’ once all of the rows have been deleted and when I try to add 'Do Until', or 'Loop Until', it doesn’t work…. </SPAN></SPAN>
I also don’t know what I would add as the 'Loop until'=(cant find the word??)</SPAN></SPAN>

Any suggestions?</SPAN></SPAN>
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,

Might be easier with a For Next loop? This code assumes the list starts in A1 ( Cells(1,1) ) and it doesn't specify the worksheet so assumes the sheet is the active sheet.

Code:
Sub test()

Dim iLRow, i As Integer

iLRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row

For i = 1 To iLRow
    If Cells(i, 1) = "Find_Word" Then
        Cells(i, 1).EntireRow.Delete
    End If
Next

End Sub
 
Upvote 0
Might be easier but I tried inputting what you have there and it doesnt fully work... it finds and deletes some of the rows but not all of them.
Need this to run until they are all gone... Even if separated by a blank cell, or if the cursor is in another cell.

What about doing Find/Select All that match a criteria, then delete all, but delete all the whole rows... I am not sure how that would look in VBA, but maybe another option? Can someone help with this?

Thanks!
 
Upvote 0
Works for me even with blanks in the list (as long as they're not at the end of column A) and doesn't matter where the curser is as long as the sheet is active.
Anyway, try this using the Find function.

Code:
Sub WordSearchRowDelete()
    Dim rng1 As Range
    Dim sSrch As String
    Application.ScreenUpdating = False
    strSrch = "Find_Word"
    Do
        Set rng1 = Range("A:A").Find(strSrch, , xlValues, xlWhole)
        If Not rng1 Is Nothing Then
            rng1.EntireRow.Delete
        End If
    Loop Until rng1 Is Nothing
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top