使用工作表名称和删除隐藏行自动过滤

问题描述 投票:-4回答:1

我想基于过滤器从excel中删除数据。根据具有指定列ex C的工作表名称过滤数据,并删除隐藏值。

我打算根据工作表名称保留数据,我已尝试使用循环,但需要很长时间才能进行处理。

wb.Activate
wb.Sheets("PMCC 1").Select
For Each ws In wb.Worksheets
    ws.Activate
    index = index + 1
    If index <= 10 Then
        irow = ws.Cells(Rows.Count, 1).End(xlUp).Row

        newtemp = Replace(ws.Name, " ", "#0")
        For J = irow To 2 Step -1
            If ws.Cells(J, 1) <> newtemp Then
                ws.Cells(J, 1).EntireRow.Delete
            End If
        Next J
    Else
        irow = ws.Cells(Rows.Count, 1).End(xlUp).Row

        newtemp = Replace(ws.Name, " ", "#")
        For J = irow To 2 Step -1
            If ws.Cells(J, 1) <> newtemp Then
                ws.Cells(J, 1).EntireRow.Delete
            End If
        Next J
    End If

Next ws

MsgBox ("Deleted")
excel vba autofilter
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.