根据单元格值循环删除多个工作表中的 table 行

loop to delete table rows through numerous worksheets based on a cell value

正在循环删除工作簿中众多作品sheet中的股票信息。每个sheet命名,"Client_ClientFirstName",每个作品sheet中的每个table与作品sheet名称相同。这是我到目前为止提出的代码,我们将不胜感激任何和所有建议。

Sub RemoveTickerFromAccounts()

Dim Client As Worksheet
Dim varTickerToFind As String
varTickerToFind = Worksheets("Entry").Cells(5, 1)


Dim tblSearchTable As Range

For Each Client In ActiveWorkbook.Worksheets

        If InStr(1, Client.Name, "Client_", vbTextCompare) Then
            'ws.Range("B30").Select
            Worksheets(Client.Name).Activate
            'tblSearchTable = ActiveSheet.ListObjects(1)

            ActiveSheet.Range("b30").Select
            If Selection.ListObject.Name = Client.Name Then
            'tblSearchTable = "Table14"


            'tblSearchTable = ActiveSheet.ListObjects(Client.Name).Select

        For i = 1 To ActiveSheet.ListObjects(Client.Name).ListRows.Count
            If ActiveSheet.ListObject.ListRows(i, 1).Value = varTickerToFind _
                Then
                tblSearchTable.ListRows(i).Delete

                Exit For
            Else
                MsgBox "Unable to Find Ticker"
                Exit For
            End If

        Next i
        End If
    End If
 Next Client


End Sub

已测试:

Sub RemoveTickerFromAccounts()

Dim Client As Worksheet
Dim varTickerToFind As String
Dim tblSearch As ListObject
Dim bFound As Boolean, i As Long

    varTickerToFind = Worksheets("Entry").Cells(5, 1).Value

    For Each Client In ActiveWorkbook.Worksheets

        If Client.Name Like "Client_*" Then

            Set tblSearch = Client.ListObjects(1)

            For i = 1 To tblSearch.ListRows.Count
                If tblSearch.ListRows(i).Range.Cells(1).Value = varTickerToFind Then
                    tblSearch.ListRows(i).Delete
                    bFound = True
                    Exit For
                End If
            Next i

            If Not bFound Then 
                MsgBox "Unable to Find Ticker '" & varTickerToFind & "'"
            End If
        End If

     Next Client
End Sub