Find/Delete macro stopped working

L

Legacy 259939

Guest
I have a macro that searches through data and finds the word TEST in column A then deletes the entire row (the test record). It worked fine for months but recently has stopped working. Nothing has changed. I cannot figure out why it is not working. Below is the code and a sample of the data.

Thanks in advance for any help!

P.S. I am using excel 2007

Code:
Sub Step_1()
'
' Step_1 Macro
'
'Deletes all TEST records
    Sheets("RawData").Select
    
    On Error Resume Next
    Dim cl As Range, c As Range
    With ActiveSheet.Range("a:a")
        Set c = .Find("TEST", LookIn:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
        Do
            Set cl = c
            Set c = .FindNext(c)
            cl.EntireRow.Delete Shift:=xlToLeft
        Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With
End Sub


[TABLE="width: 401"]
<tbody>[TR]
[TD]code
[/TD]
[TD]Cust
[/TD]
[TD]TRX_no
[/TD]
[TD]Date
[/TD]
[TD]Due Date
[/TD]
[/TR]
[TR]
[TD="align: right"]69
[/TD]
[TD]REG1
[/TD]
[TD="align: right"]91010234
[/TD]
[TD="align: right"]3/19/2014
[/TD]
[TD="align: right"]3/27/2014
[/TD]
[/TR]
[TR]
[TD="align: right"]69
[/TD]
[TD]REG1
[/TD]
[TD="align: right"]91010248
[/TD]
[TD="align: right"]3/19/2014
[/TD]
[TD="align: right"]3/27/2014
[/TD]
[/TR]
[TR]
[TD="align: right"]1
[/TD]
[TD]REG2
[/TD]
[TD="align: right"]81011128
[/TD]
[TD="align: right"]3/20/2014
[/TD]
[TD="align: right"]3/27/2014
[/TD]
[/TR]
[TR]
[TD="align: right"]1
[/TD]
[TD]REG2
[/TD]
[TD="align: right"]91012312
[/TD]
[TD="align: right"]3/21/2014
[/TD]
[TD="align: right"]3/27/2014
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]8918543
[/TD]
[TD="align: right"]9/13/2013
[/TD]
[TD="align: right"]9/23/2013
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]8921516
[/TD]
[TD="align: right"]9/19/2013
[/TD]
[TD="align: right"]9/27/2013
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]8937459
[/TD]
[TD="align: center"]########
[/TD]
[TD="align: center"]########
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]8937461
[/TD]
[TD="align: center"]########
[/TD]
[TD="align: center"]########
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]8938711
[/TD]
[TD="align: center"]########
[/TD]
[TD="align: right"]11/1/2013
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]7968354
[/TD]
[TD="align: center"]########
[/TD]
[TD="align: right"]1/2/2014
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]6968550
[/TD]
[TD="align: center"]########
[/TD]
[TD="align: right"]1/2/2014
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]7977427
[/TD]
[TD="align: right"]1/14/2014
[/TD]
[TD="align: right"]1/23/2014
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]9983051
[/TD]
[TD="align: right"]1/24/2014
[/TD]
[TD="align: right"]2/3/2014
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]8983052
[/TD]
[TD="align: right"]1/24/2014
[/TD]
[TD="align: right"]2/3/2014
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]9990282
[/TD]
[TD="align: right"]2/10/2014
[/TD]
[TD="align: right"]2/19/2014
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]9996079
[/TD]
[TD="align: right"]2/21/2014
[/TD]
[TD="align: right"]3/3/2014
[/TD]
[/TR]
[TR]
[TD]TEST
[/TD]
[TD]Test
[/TD]
[TD="align: right"]1004413
[/TD]
[TD="align: right"]3/11/2014
[/TD]
[TD="align: right"]3/19/2014
[/TD]
[/TR]
</tbody>[/TABLE]
 
Your TEST appears to be surrounded by spaces. Maybe

Code:
Sub Step_1()
'
' Step_1 Macro
'
'Deletes all TEST records
    Sheets("RawData").Select
    
    On Error Resume Next
    Dim cl As Range, c As Range
    With ActiveSheet.Range("a:a")
        Set c = .Find("TEST", LookIn:=xlValues, lookat:=xlPart)
        If Not c Is Nothing Then
            firstAddress = c.Address
        Do
            Set cl = c
            Set c = .FindNext(c)
            cl.EntireRow.Delete Shift:=xlToLeft
        Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With
End Sub
 
Upvote 0
Thank you, It works again :) Not sure why it stopped in the first place but, I will keep that trick in mind for the future.
 
Upvote 0
Well, as it turns out, this still didn't fix it. I know this sounds odd but I ran it yesterday and it worked one time. Then the next time I ran it (and all subsequent times yesterday) it didn't. Then I ran it again this morning (after shutting down my machine and restarting last night) and it worked fine. I ran it again a minute ago and it didn't.

Does anyone know why a macro would sometimes work and sometimes not? Nothing in the report I get my raw data from or the sheet it is being used in has changed. THe only thing I changed yesterday was adding the LookAt:=xlPart section as suggested.

:confused:
 
Upvote 0

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