# Deleting a word form a worksheet

#### fausat

##### New Member
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
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

#### Boller

##### Banned
"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?

#### Jonmo1

##### MrExcel MVP
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

Replies
0
Views
238
Replies
1
Views
365
Replies
0
Views
263
Replies
3
Views
265
Replies
14
Views
687

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

### 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