Delete row if a cell text equals the cell below

srschicago

Board Regular
Joined
Apr 14, 2017
Messages
59
I create a report worksheet that varies in length. The report includes "*Phase" title rows that may or may not include data rows before the next title row.
I want to delete the title rows that do not have data rows following the title row.
The cell in column C of each title row has the text "*Phase".
How do I write the code to delete the row if the text "*Phase" in cell C of the row equals the text "*Phase" in cell C of the row immediately following?
The report worksheet has a header row that does not list *Phase in the header for column C.
 
If hiker95 is correct in what he assumed your layout and desired output are, then here is another macro for you to consider. It is about 4 times faster than the code hiker95 posted, but in human terms, that time difference probably does not matter. For 500 rows of data with 80 "*Phase" entries being preserved, hiker95's macro took, on average, 0.22 seconds whereas my code took, on average, 0.04 seconds. Both times in human terms are quick enough that it should not matter which of our codes you choose unless you have tens of thousands or more rows of data.
Code:
[table="width: 500"]
[tr]
	[td]Sub DeleteAllPhasesExceptForLastOnePerGroup()
  With Sheets("REPORTS").Range("C1", Cells(Rows.Count, "C").End(xlUp))
    .Value = Evaluate("IF((REPORTS!" & .Address & "=""*Phase"")*(REPORTS!" & .Offset(1).Address & "=""*Phase""),""#N/A"",REPORTS!" & .Address & ")")
    .SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  End With
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,215,453
Messages
6,124,921
Members
449,195
Latest member
Stevenciu

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