Delete rows if specific data appears in cell, if not in cell ignore and continue

DK340

New Member
Joined
Oct 13, 2009
Messages
17
I am using the below code to search a column for a specific number, in this case 2603, and if 2603 is present it deletes the entire row.


Dim rng As Range, cell As Range, del As Range
Range("V:V").Select
Set rng = Intersect(Range("V:V"), ActiveSheet.UsedRange)
For Each cell In rng
If UCase(cell.Value) = "2603" Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next
del.EntireRow.Delete

The problem that I have is this: If the data in Range("V:V") does not have any 2603's in it, the macro fails since it did not find any 2603's. I need to know if there is something that I can add to the macro to allow the code to continue on if no 2603's exist in the data. Thanks!:confused:
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Change the last line to:
Code:
If Not del Is Nothing Then del.EntireRow.Delete
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,185
Members
449,071
Latest member
cdnMech

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