ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 982|回复: 1

[求助] 录制宏制作数据透视表录制好了用不了

[复制链接]

TA的精华主题

TA的得分主题

发表于 2018-8-8 01:13 | 显示全部楼层 |阅读模式
让调试不会调试。。。

Sub 透视表5()
'
' 透视表5 Macro
'

'
    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "081!R1C1:R1200C16", Version:=xlPivotTableVersion10).CreatePivotTable _
        TableDestination:="Sheet1!R3C1", TableName:="数据透视表1", DefaultVersion:= _
        xlPivotTableVersion10
    Sheets("Sheet1").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("数据透视表1").PivotFields("商品产地")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("数据透视表1").PivotFields("客户名称")
        .Orientation = xlRowField
        .Position = 2
    End With
    With ActiveSheet.PivotTables("数据透视表1").PivotFields("商品名称")
        .Orientation = xlRowField
        .Position = 3
    End With
    With ActiveSheet.PivotTables("数据透视表1").PivotFields("数量")
        .Orientation = xlRowField
        .Position = 4
    End With
    With ActiveSheet.PivotTables("数据透视表1").PivotFields("单位")
        .Orientation = xlRowField
        .Position = 5
    End With
    With ActiveSheet.PivotTables("数据透视表1")
        .ColumnGrand = False
        .RowGrand = False
    End With
    ActiveSheet.PivotTables("数据透视表1").ShowDrillIndicators = False
    ActiveSheet.PivotTables("数据透视表1").PivotFields("单据类型").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("单号").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("单据状态").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("单据日期").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("成本单价").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("部门名称").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("客户名称").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("商品产地").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("商品名称").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("数量").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("单位").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("商品编号").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("单价").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("金额").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("毛利").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("数据透视表1").PivotFields("交货地点").Subtotals = Array(False, _
        False, False, False, False, False, False, False, False, False, False, False)
    With ActiveSheet.PivotTables("数据透视表1").PivotFields("商品产地")
        .PivotItems("").Visible = False
        .PivotItems("(空白)").Visible = False
    End With
    Cells.Select
    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = True
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    ActiveSheet.PivotTables("数据透视表1").PivotSelect "商品名称[All]", xlLabelOnly, True
    Rows("1:2").Select
    Selection.Delete Shift:=xlUp
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = ""
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
        .RightMargin = Application.InchesToPoints(3.93700787401575E-02)
        .TopMargin = Application.InchesToPoints(3.93700787401575E-02)
        .BottomMargin = Application.InchesToPoints(3.93700787401575E-02)
        .HeaderMargin = Application.InchesToPoints(0.31496062992126)
        .FooterMargin = Application.InchesToPoints(0.31496062992126)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = 180
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlPortrait
        .Draft = False
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .EvenPage.LeftHeader.Text = ""
        .EvenPage.CenterHeader.Text = ""
        .EvenPage.RightHeader.Text = ""
        .EvenPage.LeftFooter.Text = ""
        .EvenPage.CenterFooter.Text = ""
        .EvenPage.RightFooter.Text = ""
        .FirstPage.LeftHeader.Text = ""
        .FirstPage.CenterHeader.Text = ""
        .FirstPage.RightHeader.Text = ""
        .FirstPage.LeftFooter.Text = ""
        .FirstPage.CenterFooter.Text = ""
        .FirstPage.RightFooter.Text = ""
    End With
    ActiveSheet.PivotTables("数据透视表1").PivotSelect "单位[All]", xlLabelOnly, True
    Columns("G:K").ColumnWidth = 0
    Columns("F:F").ColumnWidth = 0.15
    Columns("A:A").ColumnWidth = 9.25
    Columns("B:B").ColumnWidth = 14
    Columns("C:C").ColumnWidth = 7.75
    Columns("D:D").ColumnWidth = 4.88
    Columns("E:E").ColumnWidth = 3.75
    Columns("B:B").ColumnWidth = 13.63
    Columns("B:B").ColumnWidth = 13.5
    Range("A2:E137").Select
    Range("B3").Activate
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    ActiveWindow.SmallScroll Down:=-24
    Application.ActivePrinter = "Brother MFC-7360 Printer 在 Ne07:"
    ExecuteExcel4Macro _
        "PRINT(1,,,1,,,,,,,,2,""Brother MFC-7360 Printer 在 Ne07:"",,TRUE,,FALSE)"
End Sub


02.png

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-8-8 01:37 | 显示全部楼层
录制宏制作数据透视表录制好了用不了。附件:

附件.zip

33.88 KB, 下载次数: 0

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2025-1-11 19:58 , Processed in 0.019747 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表