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
 

Some videos you may like

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,770
When deleting rows you should always start searching form the bottom up. What column is "result" in?
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,770
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
 

Watch MrExcel Video

Forum statistics

Threads
1,090,409
Messages
5,414,236
Members
403,521
Latest member
Mattlake

This Week's Hot Topics

Top