Problem deleting rows in VB

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,047
Morning, I have a code which should be deleting a selection of cells if the word does not start with LMK or DUB or ORK but it seems to delete it even if it does, can anyone spot the error of my ways please ?

Code:
For i = LastRow To IRStartCell Step -1

K = Cells(i, 18)

If K <> "DUB*" Or K <> "LMK*" Or K <> "ORK*" Then





Range(Cells(i, 11), Cells(i, 18)).Delete


End If

Next i
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
the formula should be like this > =IF(OR(K1<>"DUB*",K1<>"LMK*",K1<>"ORK*"),1,0) I
think
ActiveCell.FormulaR1C1 = _
"=IF(OR(R[-10]C[5]<>""DUB*"",R[-10]C[5]<>""LMK*"",R[-10]C[5]<>""ORK*""),1,0)"
 
Upvote 0
Hi
Try like this:

Code:
For i = lastRow To IRStartCell Step -1
    K = Cells(i, 18).Value
    If Not K Like "DUB*" And Not K Like "LMK*" And Not K Like "ORK*" Then
        Rows(i).EntireRow.Delete
    End If
Next i
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,227
Members
448,878
Latest member
Da9l87

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