I need a code that will delete the enitre row when a specific name is typed into column A. So, for each row that has "Surgery" in column A, it needs to be deleted. Thanks.
A:
This should work. All you need to do is change the value of areaToSearch to fit your workbook. Also watch the case on the keyword, "Surgery" and "surgery" are not the same! I tested this and it worked on a sheet I made up.
Option Explicit
Sub DeleteSurgery()
Dim keyWord As String
Dim cell As Range, areaToSearch As Range
keyWord = "Surgery"
Set areaToSearch = Sheet1.Range("A1:A10")
For Each cell In areaToSearch
If cell.Value = keyWord Then
cell.EntireRow.Delete
End If
Next cell
End Sub
Michael
2010-10-07 18:46:48
Thank you Michael, but when I plug it in, it doesnt delete anything. I have an excel sheet that has a macro that creates a sheet separate from the original file. The keyword is actually MH-Surgery
Edmond
2010-10-07 20:00:44
The keyword can be anything; just change it to whatever is necessary. Are you sure you're executing the code (F5 while in the VBA editor and your cursor is within the subroutine) after pasting it in?
Michael
2010-10-07 20:13:15
It looks like the code is not executing, but I dont know why.
Edmond
2010-10-07 21:17:50