Macro to automatically delete rows based on a condition

Victtor

Board Regular
Joined
Jan 4, 2007
Messages
170
Office Version
  1. 365
Platform
  1. Windows
Hi, I need a macro to delete a row and the next 5 rows based on what is in the first row.


In Column A, wherever "Daily System Time Period Menu Items Report" appears, I need that row and the next 5 rows deleted. On the 6th row after "Daily System Time Period Menu Items Report", I need that cell in column A to equal the cell in column G.


I hope this makes sense. I have tens of thousands of rows and I need to delete unnecessary rows and make this spreadsheet smaller

Thanks in advance!!
 

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.
How about
Code:
Sub DeleteSomeRows()
   Dim Rng As Range
   Application.ScreenUpdating = False
   With Range("A2", Range("A" & Rows.count).End(xlUp))
      .Replace "Daily System Time Period Menu Items Report", True, xlWhole, , False, , False, False
      For Each Rng In .SpecialCells(xlConstants, xlLogical).Areas
         Rng.Offset(6).Value = Rng.Offset(6, 6).Value
         Rng.Resize(6).EntireRow.delete
      Next Rng
   End With
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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