VBA - How to delete rows whose cells contain

TopLearner

Board Regular
Joined
Feb 25, 2022
Messages
57
Office Version
  1. 365
Platform
  1. Windows
Hello everybody,

I hope you are well.

I have the column A with multiple cities.
A1 is the header "Location"

Then, I have the name of cities in the range A1:A200.

I also have the column B with the header "Revenue"


I would like to create a macro that delete those rows that contains "(Central)" in the "Location" column, column "A"


My attempt is


VBA Code:
Sub LimpiarFilas()

Dim ws As Worksheet
Dim cell As Range

Set ws = Sheet1


For Each cell In Range("A:A")

If cell.Value = "(Central)" Then
cell.EntireRow.Delete

End If

Next cell

End Sub


However, it is not working as cells in column A contain either cities' names like Milan or cities' names + (Central). For instance Cordoba (Central).
Then, I would like to delete the row that contains Cordoba (Central)
Would it be something like the below?

VBA Code:
IF cell.value = IF(Isnumber(match("(Central)",B1)),"Yes","No").Value = "Yes" Then
cell.entirerow.delete



Thanks
Sanchez
 
You are welcome.
Glad we were able to help!
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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