Find and delete multiple rows based on criteria

Lauradk50

New Member
Joined
Aug 29, 2008
Messages
4
Hi, I've spent days trying to resolve this and would appreciate any help. Have large data range up to 20,000 rows and need to find and delete duplicate headings within the rows (heading covers 9 rows separately). My code successfully finds and deletes the first row, but not the 8 subsequent rows. Error lies in the row that contains "resize" script below. I cannot use filtering as each heading row has similar text to some content that is to be kept, and the only unique row within the heading is the one I used to search "Report Date:" criteria.

Code:
Sub LRowDeleteHeadings()
Dim Firstrow As Long
Dim LastRow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
 
With Application
[INDENT]CalcMode = .Calculation
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
[/INDENT]End With
 
With ActiveSheet
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(14, 1).Row
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
 
'Loop from Lastrow to Firstrow (bottom to top)
For Lrow = LastRow To Firstrow Step -1
[INDENT]'Check the values in the A column
    With .Cells(Lrow, "A")
[/INDENT]   
[INDENT][INDENT]If Not IsError(.Value) Then
 
            If Trim(.Value) = "Report Date:" Then _
                .Resize(1, 9).EntireRow.Delete
        End If
[/INDENT][/INDENT]     
[INDENT]End With
[/INDENT]     
[INDENT]Next Lrow
[/INDENT]End With
 
With Application
[INDENT].ScreenUpdating = True
    .Calculation = CalcMode
[/INDENT]End With
 
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Lauradk50

Welcome to the MrExcel board!

I haven't actually tested the code, but try changing the line:
.Resize(1, 9).EntireRow.Delete
to
.Resize(9, 1).EntireRow.Delete
 
Upvote 0
Dear Peter,

THANK YOU, THANK YOU, Thank you. It worked perfectly! Ever so grateful for you help.

Kind regards
Laura :-D
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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