如何修复不展开详细信息的 ShowDetail = True
How to fix ShowDetail = True that does not expand details
以下代码在没有 run-time 错误并且使用正确数据生成枢轴 table 并放置在正确位置的意义上运行良好。
但是,项目列表已折叠。
部分代码包含在:
- 从数组中读取列头
- 识别可以在一个范围内随机放置的列标题
- 对于每一列,构建一个one-dimension(即单个字段)pivot-table
- 将枢轴 table 放在给定位置
- 显示所有项目 + 它们的数量
A) 使用 SHOWDETAIL = True
B) 录制宏和"cloning"代码
For Each headerCell In wSh.Range("Ctl_Headers")
Set sceRange = wSh.Range(headerCell.Value)
sceRange.Activate
fRow = sceRange.Row
lRow = sceRange.Cells.SpecialCells(xlCellTypeLastCell).Row
fCol = sceRange.Column
lCol = fCol - 1 + sceRange.Columns.Count
Set pivCache = wBk.PivotCaches.Add(xlDatabase, wSh.Range(wSh.Cells(fRow, fCol), wSh.Cells(lRow, lCol)))
Set pivTable = wSh.PivotTables.Add(PivotCache:=pivCache, TableDestination:=wSh.Range(wSh.Cells(1, nrindex), wSh.Cells(1, nrindex)), TableName:="piv" & headerCell.Value)
pivTable.PivotFields(headerCell.Value).Orientation = xlRowField
pivTable.AddDataField pivTable.PivotFields(headerCell.Value), "Count " & headerCell.Value, xlCount
pivTable.PivotFields(headerCell.Value).ShowDetail = True
nrindex = nrindex + 4
Next headerCell
您将 pivTable.PivotFields(headerCell.Value)
用作 RowField
,并将其计数为 DataField
。
您必须更改以下代码行以解决行字段问题。
之前:
pivTable.PivotFields(headerCell.Value).ShowDetail = True
之后:
pivTable.RowFields(headerCell.Value).ShowDetail = True
以下代码在没有 run-time 错误并且使用正确数据生成枢轴 table 并放置在正确位置的意义上运行良好。
但是,项目列表已折叠。
部分代码包含在:
- 从数组中读取列头
- 识别可以在一个范围内随机放置的列标题
- 对于每一列,构建一个one-dimension(即单个字段)pivot-table
- 将枢轴 table 放在给定位置
- 显示所有项目 + 它们的数量
A) 使用 SHOWDETAIL = True
B) 录制宏和"cloning"代码
For Each headerCell In wSh.Range("Ctl_Headers")
Set sceRange = wSh.Range(headerCell.Value)
sceRange.Activate
fRow = sceRange.Row
lRow = sceRange.Cells.SpecialCells(xlCellTypeLastCell).Row
fCol = sceRange.Column
lCol = fCol - 1 + sceRange.Columns.Count
Set pivCache = wBk.PivotCaches.Add(xlDatabase, wSh.Range(wSh.Cells(fRow, fCol), wSh.Cells(lRow, lCol)))
Set pivTable = wSh.PivotTables.Add(PivotCache:=pivCache, TableDestination:=wSh.Range(wSh.Cells(1, nrindex), wSh.Cells(1, nrindex)), TableName:="piv" & headerCell.Value)
pivTable.PivotFields(headerCell.Value).Orientation = xlRowField
pivTable.AddDataField pivTable.PivotFields(headerCell.Value), "Count " & headerCell.Value, xlCount
pivTable.PivotFields(headerCell.Value).ShowDetail = True
nrindex = nrindex + 4
Next headerCell
您将 pivTable.PivotFields(headerCell.Value)
用作 RowField
,并将其计数为 DataField
。
您必须更改以下代码行以解决行字段问题。
之前:
pivTable.PivotFields(headerCell.Value).ShowDetail = True
之后:
pivTable.RowFields(headerCell.Value).ShowDetail = True