VBA Delete multiple rows based on find criteria

wendya

New Member
Joined
Feb 21, 2017
Messages
2
Hi Everyone,

I am a newbie! I was hoping for some assistance with the following code. I am looking to have this code, find the criteria in a sheet and delete ALL rows with that criteria. This code only deletes the first record it comes across. I tried to play with a loop but I am not sure how to end it, and keep resulting in errors. Can anyone help, please? I am sure it is an easy fix... but every code I look at on while searching keeps giving me errors. This looks at a field "Reg4" value and then deletes the line off the sheet.

Code:
'delete the rows from quotes sheet
        Set findvalue = Sheet10.Range("a:a").Find(What:=Reg4, LookIn:=xlValues)
        findvalue.EntireRow.Delete
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hello Wendya,

can you post whole code including variables definitions etc? .. Thank you.

regards,
Tom
 
Upvote 0
Try this, maybe it could be helpful ( you must define your reg4 variable again)....

Code:
Sub test()

Dim i As Integer
Dim lr As Long

below pls specify your variable
'dim reg4 as ?????

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

For i = lr To 1 Step -1

If Cells(i, 1) = reg4 Then
    Rows(i).Delete
End If


Next

        
        
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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