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.

[TABLE="width: 314"]
<tbody>[TR]
[TD="width: 418, bgcolor: transparent, colspan: 3"]OPEN WORK REPORT
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: transparent"]Period
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: #D9D9D9"]NUMBER
[/TD]
[TD="width: 204, bgcolor: #D9D9D9"]WORK ORDER
[/TD]
[TD="width: 124, bgcolor: #D9D9D9"]DESCRIPTION
[/TD]
[/TR]
[TR]
[TD="width: 204, bgcolor: #D9D9D9"]TYPE
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25524484
[/TD]
[TD="width: 204, bgcolor: white"]ACCIDENT
[/TD]
[TD="width: 124, bgcolor: white"]accident rollover
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: transparent"]Period
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: #D9D9D9"]NUMBER
[/TD]
[TD="width: 204, bgcolor: #D9D9D9"]WORK ORDER
[/TD]
[TD="width: 124, bgcolor: #D9D9D9"]WORK ORDER DESCRIPTION
[/TD]
[/TR]
[TR]
[TD="width: 204, bgcolor: #D9D9D9"]TYPE
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25858720
[/TD]
[TD="width: 204, bgcolor: white"]BULK ISSUE
[/TD]
[TD="width: 124, bgcolor: white"]Bulk Issue Parts
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25858729
[/TD]
[TD="width: 204, bgcolor: white"]SERVICING
[/TD]
[TD="width: 124, bgcolor: white"]Bulk Oil
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791362
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791353
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791366
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791369
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791377
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791379
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791382
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25801712
[/TD]
[TD="width: 204, bgcolor: white"]ACCIDENT
[/TD]
[TD="width: 124, bgcolor: white"]ACCIDENT
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25933250
[/TD]
[TD="width: 204, bgcolor: white"]ACCIDENT
[/TD]
[TD="width: 124, bgcolor: white"]ACCIDENT
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: transparent"]Period
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: #D9D9D9"]NUMBER
[/TD]
[TD="width: 204, bgcolor: #D9D9D9"]WORK ORDER
[/TD]
[TD="width: 124, bgcolor: #D9D9D9"]WORK ORDER DESCRIPTION
[/TD]
[/TR]
[TR]
[TD="width: 204, bgcolor: #D9D9D9"]TYPE
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791353
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791366
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791369
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 503"]
<tbody>[TR]
[TD="width: 670, bgcolor: transparent"]
I want to delete the row begging with Period and also the next 2 rows with a result like below.

[TABLE="width: 314"]
<tbody>[TR]
[TD="width: 418, bgcolor: transparent, colspan: 3"]OPEN WORK REPORT
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25524484
[/TD]
[TD="width: 204, bgcolor: white"]ACCIDENT
[/TD]
[TD="width: 124, bgcolor: white"]accident rollover
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25858720
[/TD]
[TD="width: 204, bgcolor: white"]BULK ISSUE
[/TD]
[TD="width: 124, bgcolor: white"]Bulk Issue Parts
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25858729
[/TD]
[TD="width: 204, bgcolor: white"]SERVICING
[/TD]
[TD="width: 124, bgcolor: white"]Bulk Oil
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791362
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791353
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791366
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791369
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791377
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791379
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791382
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25801712
[/TD]
[TD="width: 204, bgcolor: white"]ACCIDENT
[/TD]
[TD="width: 124, bgcolor: white"]ACCIDENT
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25933250
[/TD]
[TD="width: 204, bgcolor: white"]ACCIDENT
[/TD]
[TD="width: 124, bgcolor: white"]ACCIDENT
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791353
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791366
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
[TR]
[TD="width: 90, bgcolor: white, align: right"]25791369
[/TD]
[TD="width: 204, bgcolor: white"] MAINTENANCE
[/TD]
[TD="width: 124, bgcolor: white"]PMI
[/TD]
[/TR]
</tbody>[/TABLE]

Here is the code that I have but it only deletes the row with Period in it.[/TD]
[/TR]
</tbody>[/TABLE]

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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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