开发者

Creating a macro to delete rows in Excel using VB

I need a code that will delete the enitre row w开发者_StackOverflowhen a specific name is typed into column A. So, for each row that has "Surgery" in column A, it needs to be deleted. Thanks.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜