Using excel VBA delete multiple lines in a active sheet

Coosa41

New Member
Joined
May 8, 2019
Messages
6
Here is an example of what I have and what I would like to accomplish.

OPEN WORK REPORT
Period
NUMBER
WORK ORDER
DESCRIPTION
TYPE
25524484
ACCIDENT
accident rollover
Period
NUMBER
WORK ORDER
WORK ORDER DESCRIPTION
TYPE
25858720
BULK ISSUE
Bulk Issue Parts
25858729
SERVICING
Bulk Oil
25791362
MAINTENANCE
PMI
25791353
MAINTENANCE
PMI
25791366
MAINTENANCE
PMI
25791369
MAINTENANCE
PMI
25791377
MAINTENANCE
PMI
25791379
MAINTENANCE
PMI
25791382
MAINTENANCE
PMI
25801712
ACCIDENT
ACCIDENT
25933250
ACCIDENT
ACCIDENT
Period
NUMBER
WORK ORDER
WORK ORDER DESCRIPTION
TYPE
25791353
MAINTENANCE
PMI
25791366
MAINTENANCE
PMI
25791369
MAINTENANCE
PMI

<tbody>
</tbody>


I want to delete the row begging with Period and also the next 2 rows with a result like below.

OPEN WORK REPORT
25524484
ACCIDENT
accident rollover
25858720
BULK ISSUE
Bulk Issue Parts
25858729
SERVICING
Bulk Oil
25791362
MAINTENANCE
PMI
25791353
MAINTENANCE
PMI
25791366
MAINTENANCE
PMI
25791369
MAINTENANCE
PMI
25791377
MAINTENANCE
PMI
25791379
MAINTENANCE
PMI
25791382
MAINTENANCE
PMI
25801712
ACCIDENT
ACCIDENT
25933250
ACCIDENT
ACCIDENT
25791353
MAINTENANCE
PMI
25791366
MAINTENANCE
PMI
25791369
MAINTENANCE
PMI

<tbody>
</tbody>

Here is the code that I have but it only deletes the row with Period in it.

<tbody>
</tbody>

Sub Delete_Rows()
Dim lRow As Long
Dim iCntr As Long
lRow = 20
For iCntr = lRow To 1 Step -1
If Cells(iCntr, 1) = "Period" Then
Rows(iCntr).Delete
End If
Next
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi & welcome to MrExcel
How about
Code:
Sub Coosa41()
   Dim Cl As Range
   With Range("A1", Range("A" & Rows.Count).End(xlUp))
      .Replace "Period", True, xlWhole, , False, , False, False
      For Each Cl In .SpecialCells(xlConstants, xlLogical).Areas
         Cl.Resize(3).EntireRow.Delete
      Next Cl
   End With
End Sub
 
Upvote 0
Thank You for your time and help. This does exactly what I was looking to accomplish.

Again

Thank You
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,559
Members
449,089
Latest member
Motoracer88

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