我需要此VBA代码才能在整个工作簿中使用

时间:2018-07-06 19:05:56

标签: excel-vba vba excel

Sub DeleteRows()
    Dim c As Range
    Dim SrchRng As Range
    Dim SrchStr As String

    Set SrchRng = ActiveSheet.Range("b1", ActiveSheet.Range("b65536").End(xlUp))
    SrchStr = Range("k1")
    Do
        Set c = SrchRng.Find(SrchStr, LookIn:=xlValues)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

也许是这样

Sub DeleteRows()
Dim c As Range
Dim SrchRng As Range
Dim SrchStr As String
Dim sh As Worksheet

    For Each sh In ActiveWorkbook.Worksheets
        Set SrchRng = sh.Range("b1", sh.Range("b65536").End(xlUp))
        SrchStr = sh.Range("k1")
        Do
            Set c = SrchRng.Find(SrchStr, LookIn:=xlValues)
            If Not c Is Nothing Then c.EntireRow.Delete
        Loop While Not c Is Nothing
    Next

End Sub