1
4

2 回答 2

2

这是手动执行此操作的方法:

  • 创建数据透视表
  • 将商店类型拖动到过滤器(页面字段)区域
  • 将卖家和商品拖到行字段区域
  • 将价格拖到值区域
  • 现在单击功能区的“分析”选项卡,然后选择“选项”、“显示报告过滤器页面”。
  • 选择商店类型,然后单击确定。
于 2018-09-13T15:08:55.980 回答
1

详细信息作为评论。

Sub splitStores()

    Dim i As Long, k As Variant, stores As Object

    Set stores = CreateObject("scripting.dictionary")
    stores.comparemode = vbTextCompare

    With ThisWorkbook.Worksheets("sheet9")
        If .AutoFilterMode Then .AutoFilterMode = False

        'create unique list of stores
        For i = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
            stores.Item(.Cells(i, "A").Value2) = vbNullString
        Next i

        'cycle through the stores
        For Each k In stores.keys

            'create a new active workbook with all records
            .Cells.Parent.Copy

            With ActiveWorkbook.Worksheets(1)

                'rename the worksheet
                .Name = k

                'setup the autofilter area
                With .Cells(1, 1).CurrentRegion

                    'filter to show anything but current store
                    .AutoFilter field:=1, Criteria1:="<>" & k

                    'delete all unrelated records
                    .Offset(1, 0).EntireRow.Delete

                    'turn filter off
                    .Parent.AutoFilterMode = False

                End With

                'save and close independent workbook
                .Parent.SaveAs Filename:=ThisWorkbook.Path & "\" & k, FileFormat:=xlOpenXMLWorkbook
                .Parent.Close savechanges:=False

            End With

        Next k

    End With
End Sub
于 2018-09-13T15:13:30.163 回答