Delete Row where value in column equals a value in a designated cell

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
How do I change this code from deleting the row where there is "Parent" to deleting if the value equals whats In cell B1?

Need to Start in Row 4

Code:
Sub DeleteParentRows2()
'Delete Rows that have "Parent" in column B

Dim X As Long, lastrow As Long

Sheets("Children").Activate

lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row

For X = lastrow To 1 Step -1
    If Cells(X, 2).Value = "Parent" Then Cells(X, 2).Delete Shift:=xlUp
Next X

ActiveSheet.Name = Range("$C$1").Value

End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Just reference B1:

If Cells(X, 2).Value = Range("B1).Value Then Cells(X, 2).Delete Shift:=xlUp
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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