Simple VBA Help Needed - Search for a Value and Delete Row

jrega17

New Member
Joined
Oct 3, 2013
Messages
9
Hi - I created the following code to find the word "result" on a worksheet and if found, delete the row. The code below works but displays an error after it runs:
Object Variable or With block variable not set
The error relates to the code highlighted in blue below:

Sub FindResult()


Dim i As Integer


For i = 1 To 10
Cells.find(What:="Result", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.EntireRow.Select
Selection.Delete Shift:=xlUp

Next i
Range("A1").Activate


End Sub

----------
I am not sure what I need to include to tweak the code. Any help would be appreciated. Thank you! - J
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
When deleting rows you should always start searching form the bottom up. What column is "result" in?
 
Upvote 0
Try:
Code:
Sub DelRows()
    Application.ScreenUpdating = False
    Dim bottomC As Long
    bottomC = Range("C" & Rows.Count).End(xlUp).Row
    Dim x As Long
    For x = bottomC To 2 Step -1
        If Cells(x, "C") = "results" Then
            Rows(x).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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