Hi, I just started working with variables and not sure I understand them. I have the following code that basically seaches a range and if the specified value doesn't appear, the row will be deleted. This works for the first sheet that is referenced but not for the second. Originally, I had defined the variables in both pieces and got an error about "duplicate declaration in current scope". I thought the correct thing to do was to move the dim statements to the top of the code and they only appear once but my code still does not work for the second sheet (although I don't get the error any longer). I'd appreciate some help. Thanks.
Code:
Dim rng As Range, cell As Range, del As Range
Dim strCellValue As String
Sheets("ABC").Select
Set rng = Intersect(Range("D7:D10006"), ActiveSheet.UsedRange)
For Each cell In rng
strCellValue = (cell.Value)
If InStr(strCellValue, "Dog") = 0 Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete
Sheets("XYZ").Select
Set rng = Intersect(Range("D7:D10006"), ActiveSheet.UsedRange)
For Each cell In rng
strCellValue = (cell.Value)
If InStr(strCellValue, "Cat") = 0 Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete