What is the fastest way to clear the contents of all rows after the row that contains the word “Total”? I can search for the word and then use offset to get to the next row. But then I don’t know how to say from this row on, clear all content.
TIA
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Clear Row Contents (Excel 97 SR2)
Dim c As Range With ActiveSheet Set c = .Cells.Find(What:="Total", After:=.Cells(1), LookIn:=xlValues, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=True) If Not c Is Nothing Then _ .Rows(c.Row + 1 & ":" & .UsedRange.Row + .UsedRange.Rows.Count).Delete End With Set c = Nothing
Sam,
The code I already have in place starts out with For each ws in Worksheets and then proceeds to do a series of actions on each sheet. I took your code and inserted it minus the With ActiveSheet to see if it would work. I get a Compile Error that says Invalid or unqualified reference and the error message highlights the code =.Cells as bolded here:
Set c = .Cells.Find(What:=”Total”, After:=.Cells(1), LookIn:=xlValues, _ etc.
BTW, I did try the code as is as a stand alone and it worked fine, clearing the contents of all rows after the row containing the word TOTAL. Now I just need to figure out how to get it to work inside my current code.
TIA
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications