Need to delete rows after a specific text is found

zookeepertx

Active Member
Joined
May 27, 2011
Messages
484
I've been trying to figure this out on my own, but am just beating my head into a wall. So, I surrender & am hoping someone can tell me where my error is.

I have a report that shows data broken up into age ranges: 1-30 days, 31-60 days, etc. The age range info is found in column B. I want to delete the next 6 rows after each age range header. (All headers look like: Age Range: 0-30. No of recaps 23)

Here's what I've arrived at most recently (just one of many things I've tried), but it just runs through & doesn't actually DO anything. At least it doesn't give me any annoying error messages, so there's that. :rolleyes:

Code:
Sub ClearingTB()
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
        .DisplayAlerts = False
    End With
 
    LR = Range("B" & Rows.count).End(xlUp).Row
    LC = Cells(12, Columns.count).End(xlToLeft).Column
 
    For i = 1 To LR
        If Range("B" & i).Value = "Age Range:*" Then
        Rows("i + 1 : i + 6").Delete
        End If
    Next i
 
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
    End With
 
End Sub

If someone can show me this, I think I can figure out from there how to do the rest of what needs done on this report.

Thanks!

Jenny
 
Last edited:

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
The wildcard isn't going to work there...
Try the like operator...

If Range("B" & i).Value Like "Age Range:*" Then


Also, you may want to make your loop go backwards (bottom to top)

change
i = 1 To LR
to
i = LR To 1 Step -1


Hope that helps.
 

zookeepertx

Active Member
Joined
May 27, 2011
Messages
484
Hi Jonmo!

That does make it recognize & TRY to do the deleting, but gives back a "runtime 13 error 13: Type mismatch" on the
Code:
Rows("i + 1 : i + 6").Delete
I assume I have my syntax wrong in there.

Thanks

Jenny
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Ah, yes...

That should probably by

Rows(i + 1 & ":" & i + 6).Delete
 

Watch MrExcel Video

Forum statistics

Threads
1,123,085
Messages
5,599,650
Members
414,325
Latest member
kfg1287

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
Top