Help with My Delete Row Macro

JADownie

Active Member
Joined
Dec 11, 2007
Messages
395
Essentially what I wanted this macro to do was search column O and if the value in the row did not equal "External" then it would delete the entire row.

But the macro I tried to write below is deleting every row...

Any insight would be greatly appreciated! Thanks!



Sub Delete_Internals()
Sheets("Data Format Sheet").Select
ActiveWindow.SmallScroll Down:=-24
Range("A1").Select
Dim LR As Long, i As Long
LR = Range("O" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
If Not Range("O" & i).Value Like "External" Then Rows(i).Delete
Next i
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try

Code:
Sub Delete_Internals()
Dim LR As Long, i As Long
With Sheets("Data Format Sheet")
    LR = .Range("O" & Rows.Count).End(xlUp).Row
    For i = LR To 2 Step -1
        If Not .Range("O" & i).Value Like "*External*" Then .Rows(i).Delete
    Next i
End With
End Sub
 
Upvote 0
Thanks! That worked! :)

Is it possible to make this look for cells that do not equal External OR Other? And delete rows?
 
Upvote 0
Try

Code:
Sub Delete_Internals()
Dim LR As Long, i As Long
With Sheets("Data Format Sheet")
    LR = .Range("O" & Rows.Count).End(xlUp).Row
    For i = LR To 2 Step -1
        If Not .Range("O" & i).Value Like "*External*" _
            And Not .Range("O" & i).Value Like "*Other*" Then .Rows(i).Delete
    Next i
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,510
Members
448,967
Latest member
screechyboy79

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