ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[求助] 录制的宏,为何不能运行(制作数据透视表)

[复制链接]

TA的精华主题

TA的得分主题

发表于 2006-11-20 17:18 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

各位老师:

     我录制了一段制作数据透视表宏 (指定将数据透视表放在工作表名(进度表), 但测试不能运行, 请高手指点,到底应如何调试.

不胜感激之至!

谢谢

 Private Sub CommandButton1_Click()
    Range("F6").Select
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "生产明细!R1C1:R10000C13").CreatePivotTable TableDestination:= _
        "[产能分析.xls]进度表!R3C1", TableName:="数据透视表1", DefaultVersion:= _
        xlPivotTableVersion10
    ActiveSheet.PivotTables("数据透视表1").AddFields RowFields:=Array("批号", "工序", "数据")
    With ActiveSheet.PivotTables("数据透视表1").PivotFields("FZ_SL")
        .Orientation = xlDataField
        .Caption = "发出"
        .Position = 1
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("数据透视表1").PivotFields("JH_SL")
        .Orientation = xlDataField
        .Caption = "收回"
        .Position = 2
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("数据透视表1").PivotFields("欠数")
        .Orientation = xlDataField
        .Caption = "欠收"
        .Function = xlSum
    End With
    ActiveWorkbook.ShowPivotTableFieldList = False
    Range("C3").Select
    With ActiveSheet.PivotTables("数据透视表1").DataPivotField
        .Orientation = xlColumnField
        .Position = 1
    End With
    Columns("C:E").Select
    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
End Sub

TwDWGvCQ.rar (74.06 KB, 下载次数: 101)

TA的精华主题

TA的得分主题

发表于 2006-11-21 09:01 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
Private Sub CommandButton1_Click()
    Range("F6").Select
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "生产明细!R1C1:R10000C13").CreatePivotTable TableDestination:= _
        "进度表!R3C1", TableName:="数据透视表1", DefaultVersion:= _
        xlPivotTableVersion10
    Sheet18.PivotTables("数据透视表1").AddFields RowFields:=Array("批号", "工序", "数据")
    With Sheet18.PivotTables("数据透视表1").PivotFields("FZ_SL")
        .Orientation = xlDataField
        .Caption = "发出"
        .Position = 1
        .Function = xlSum
    End With
    With Sheet18.PivotTables("数据透视表1").PivotFields("JH_SL")
        .Orientation = xlDataField
        .Caption = "收回"
        .Position = 2
        .Function = xlSum
    End With
    With Sheet18.PivotTables("数据透视表1").PivotFields("欠数")
        .Orientation = xlDataField
        .Caption = "欠收"
        .Function = xlSum
    End With
    ActiveWorkbook.ShowPivotTableFieldList = False
    With Sheet18.PivotTables("数据透视表1").DataPivotField
        .Orientation = xlColumnField
        .Position = 1
    End With
    With Sheet18.Columns("C:E")
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Sheet18.Columns("C:E")
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-11-21 09:32 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-11-23 17:01 | 显示全部楼层

各位老师:

    如下附蓝色字体的代码(DefaultVersion:= _xlPivotTableVersion10)
为何在EXCEL 2000版本中不能运行, 出现提示为"编译错误:“未找到命名参数”应如何调试。

请老师们指点。

Private Sub CommandButton1_Click()
    Range("F6").Select
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "生产明细!R1C1:R10000C13").CreatePivotTable TableDestination:= _
        "进度表!R3C1", TableName:="数据透视表1", DefaultVersion:= _
        xlPivotTableVersion10
    Sheet18.PivotTables("数据透视表1").AddFields RowFields:=Array("批号", "工序", "数据")
    With Sheet18.PivotTables("数据透视表1").PivotFields("FZ_SL")
        .Orientation = xlDataField
        .Caption = "发出"
        .Position = 1
        .Function = xlSum
    End With
    With Sheet18.PivotTables("数据透视表1").PivotFields("JH_SL")
        .Orientation = xlDataField
        .Caption = "收回"
        .Position = 2
        .Function = xlSum
    End With
    With Sheet18.PivotTables("数据透视表1").PivotFields("欠数")
        .Orientation = xlDataField
        .Caption = "欠收"
        .Function = xlSum
    End With
    ActiveWorkbook.ShowPivotTableFieldList = False
    With Sheet18.PivotTables("数据透视表1").DataPivotField
        .Orientation = xlColumnField
        .Position = 1
    End With
    With Sheet18.Columns("C:E")
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Sheet18.Columns("C:E")
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
End Sub

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

本版积分规则

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

GMT+8, 2024-11-25 18:55 , Processed in 0.031925 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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