Add input box to a Macro - Find word and delete row

Need Help Please

Board Regular
Joined
Jul 7, 2009
Messages
64
I have a macro that works and find the word total in a spreadsheet and deletes the entire row. I also would like to delete other rows like Grand Total and Account Name. Can someone tell me how to add an input box to this code or modify the code so it can ask for a word then delete all rows that have that word in it. Thanks in advance!!!

Here is the code:

Code:
Sub DeleteRows()
 
Dim rFound As Range, Str As String
Application.ScreenUpdating = True
On Error Resume Next

Str = "total"

Do
    Set rFound = Cells.Find(Str, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows)
    If Not rFound Is Nothing Then Rows(rFound.Row).EntireRow.Delete xlShiftUp
Loop Until rFound Is Nothing

Application.ScreenUpdating = True
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try something like this...
Code:
    Str = Application.InputBox("Enter word to search for.", "Delete Rows with Word", "total", Type:=2)
    If Str = "False" Then Exit Sub  'User canceled

Also, it's not a good idea to use On Error Resume Next to ignore all errors. How would you know if you have a problem?

Application.InputBox
 
Last edited:
Upvote 0
Great, thanks so much for your help. This helps. I've only used VBA two other times and I copied part of the code I found. I appreciate your tip on the on error resume, I will remove this. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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