收藏 分享(赏)

VBA实战——创建数据透视表.doc

上传人:HR专家 文档编号:11441762 上传时间:2020-04-28 格式:DOC 页数:3 大小:15.14KB
下载 相关 举报
VBA实战——创建数据透视表.doc_第1页
第1页 / 共3页
VBA实战——创建数据透视表.doc_第2页
第2页 / 共3页
VBA实战——创建数据透视表.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、Sub 创建数据透视表() ActiveWorkbook.Names.Add Name:=database1, RefersToR1C1:= _ =OFFSET(R4C3,COUNTA(C3),COUNTA(R4) ActiveWorkbook.Names(database1).Comment = Rows(5:5).Select Selection.Delete Shift:=xlUp Range(C4).Select Sheets.Add ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ dat

2、abase1, Version:=xlPivotTableVersion14).CreatePivotTable _ TableDestination:=Sheet1!R3C1, TableName:=数据透视表1, DefaultVersion:= _ xlPivotTableVersion14 Sheets(Sheet1).Select Cells(3, 1).Select With ActiveSheet.PivotTables(数据透视表1).PivotFields(指令单单号) .Orientation = xlPageField .Position = 1 End With Wit

3、h ActiveSheet.PivotTables(数据透视表1).PivotFields(名称 1) .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

4、With With ActiveSheet.PivotTables(数据透视表1).PivotFields(物料描述) .Orientation = xlRowField .Position = 4 End With With ActiveSheet.PivotTables(数据透视表1).PivotFields(供应商) .Orientation = xlRowField .Position = 5 End With ActiveSheet.PivotTables(数据透视表1).AddDataField ActiveSheet.PivotTables(数据透视表1 _ ).PivotFie

5、lds(需求量), 求和项:需求量, xlSum Range(B21).Select With ActiveSheet.PivotTables(数据透视表1) .InGridDropZones = True .RowAxisLayout xlTabularRow End With Range(D6).Select ActiveSheet.PivotTables(数据透视表1).PivotFields(物料描述).Subtotals = Array(False, _ False, False, False, False, False, False, False, False, False, Fa

6、lse, False) Range(C6).Select ActiveSheet.PivotTables(数据透视表1).PivotFields(物料).Subtotals = Array(False, _ False, False, False, False, False, False, False, False, False, False, False) Range(B6).Select ActiveSheet.PivotTables(数据透视表1).PivotFields(作业).Subtotals = Array(False, _ False, False, False, False,

7、 False, False, False, False, False, False, False) Range(A7).Select ActiveSheet.PivotTables(数据透视表1).PivotFields(名称 1).Subtotals = Array(False, _ False, False, False, False, False, False, False, False, False, False, False) ActiveSheet.PivotTables(数据透视表1).PivotSelect , xlDataAndLabel, True Selection.Bo

8、rders(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 .TintAndSha

9、de = 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 With Selection.Borders

10、(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With Range(A13).Select ActiveSheet.PivotTables(数据透视表1).ShowDrillIndicat

11、ors = False Columns(A:A).ColumnWidth = 7.88 Columns(B:F).Select With Selection .HorizontalAlignment = xlLeft .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Columns(B:F).E

12、ntireColumn.AutoFit ActiveSheet.PivotTables(数据透视表1).PivotSelect 物料描述All, xlLabelOnly, True Columns(F:F).Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End WithEnd Sub

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 网络科技 > 计算机原理

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报