Deleting a word form a worksheet

fausat

New Member
Joined
Jul 17, 2007
Messages
1
Hi

I am new to Macros and hoping this website will support me in learning and grasping the concept of macros. I need to write a macro that will delete a row in a work sheet with with the work total.

Thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

ravishankar

Well-known Member
Joined
Feb 23, 2006
Messages
3,566
Hi
Assuming you are searching the word total in col A
Paste the following codes in the macro window(alt f8)
Code:
x = Cells(Rows.Count, 1).End(xlUp).Row
For a = 1 To x
If InStr(Cells(a, 1), "Total") > 0 Then
Rows(a).Delete
End If
Next a
Run the macro
It will delete all rows containing the word "Total" (Ensure uppercase and lower case letters match)
Ravi
 
Upvote 0

Boller

Banned
Joined
Apr 11, 2006
Messages
2,328
"the work total"

Do you mean "the word "total" " ?

If so, is there a particular column that you want to search?

Do you want to find one cell only, or might there be more than one cell?

Do you want to find cell(s) where the whole cell equals "total", or only cell(s) where "total" is part of the cell?
 
Upvote 0

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
ravishankar,

I think you'll need to make that go backwards, from the last row working up. Otherwise, if there is Total in 2 rows in a row, it will skip the 2nd.

if you have Total in A1 and A2, only row 1 will be deleted. Because after deleting row 1, what was in row 2 is now in row 1. Then it loops and it will be looking at row 2 next.

Code:
x = Cells(Rows.Count, 1).End(xlUp).Row
For a = x To 1 Step -1
If InStr(Cells(a, 1), "Total") > 0 Then
Rows(a).Delete
End If
Next a
 
Upvote 0

Forum statistics

Threads
1,191,719
Messages
5,988,295
Members
440,148
Latest member
sandy123

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