Conditional formatting VBA for not equal to

timot18

New Member
Joined
Dec 9, 2004
Messages
33
Hi, I am trying to delete rows in a list if one of the cells does not equal certain text. I think I am being stupid. At present I am using the code:

Range("d65536").End(xlUp).Select
While ActiveCell.Row > 1
If ActiveCell Like "*=*" Then ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select

Wend

But I want the row to be deleted if the Active cell DOES NOT have certain text in it. Can someone quickly help me.

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi I have put in the following code:

Sub Delete_Search()

Range("d65536").End(xlUp).Select
While ActiveCell.Row > 1
If InStr(1, ActiveCell, "*=*") > 0 Then ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select

Wend

I want the macro to delete rows where cells in column D to not have an "=" sign. And unfortunately this does not work. Any ideas?

Thanks
 
Upvote 0
1. The *s around = are not needed.

2. If the `=' is part of a text entry in the cell, this will work.

3. If your checking whether the cell has a formula, this will not work. Instead try If ActiveCell.HasFormula
 
Upvote 0
The code that was given deletes all rows where the value in active cell is present. I am hoping to find code that deletes rows where the value in the active cell is NOT present.

Sorry for any confusion

Tim. :wink:
 
Upvote 0
My mistake. change the line to:

If InStr(1, ActiveCell, "*=*") = 0 Then ActiveCell.EntireRow.Delete
 
Upvote 0
Thanks thats great. I know its cheeky but can you tell me how to stop the loop when it hits line 4 i have been using the following but it doesnt seem to work:

Sub Delete_Search()

Range("d65536:d4").End(xlUp).Select
While ActiveCell.Row > 1
If InStr(1, ActiveCell, "=") = 0 Then ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select

Wend

End Sub

Thanks
 
Upvote 0
Try:

Code:
Dim LastRow as Long
LastRow = [D65536].End(xlUp).Row
Do while LastRow > 3
     With Range("D" & LastRow)
            If InStr(1, .Value, "=") = 0 Then .EntireRow.Delete
      End With
      LastRow = LastRow -1
Loop
 
Upvote 0

Forum statistics

Threads
1,222,562
Messages
6,166,805
Members
452,073
Latest member
akinch

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