code to delete rows after row containg "End of report&q

dennisli

Well-known Member
Joined
Feb 20, 2004
Messages
1,070
Good morning,
Can you gurus provide a code to delete all the used rows after the row containing “End of report” in column A.
Thanks lot.
Dennis
 
This is the new code error message:

Run-time error “1004”
Method ‘Range’ of object’_Global’ failed

Thanks lot.

Dennis
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Okay, my mistake. :oops: Try this:
Code:
Sub Delete_Rows()
Dim Mycell As Range
Dim Tcell As Range

With Range("A:A")
      Set Mycell = .Find(What:="End of report", After:=Range("A1"), LookIn:= _
        xlFormulas)
End With

For Each Tcell In Range(Mycell.Offset(1), Range("A65536"))
       If Tcell.Value <> "" Then
                Tcell.EntireRow.ClearContents
        End If
Next Tcell

End Sub
 
Upvote 0
Sorry, Sir,
I am back again.
If there is no End of report in the range, the code gets an error message:

Run-time error ‘91’:
Object variable or with block variable not set.

What should I do?

Thanks lot.
Dennis
 
Upvote 0
Just change to this:

Code:
Sub Delete_Rows()
Dim Mycell As Range
Dim Tcell As Range

With Range("A:A")
      Set Mycell = .Find(What:="End of report", After:=Range("A1"), LookIn:= _
        xlFormulas)
End With

If Not Mycell Is Nothing Then
        For Each Tcell In Range(Mycell.Offset(1), Range("A65536"))
               If Tcell.Value <> "" Then
                        Tcell.EntireRow.ClearContents
                End If
        Next Tcell
Else
       MsgBox "No End of report found"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,175
Messages
6,129,310
Members
449,499
Latest member
HockeyBoi

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