|
▼しいな さん:
こんな感じで
Option Explicit
Sub test()
Dim dic As Object
Dim ws As Worksheet
Dim c As Range
Dim e
Dim n As Long
Dim r As Range
Dim fn
Dim pvt As PivotTable
Set dic = CreateObject("scripting.dictionary")
Set ws = ActiveSheet
For Each c In ws.Range("B1", ws.Range("B10000").End(xlUp))
For Each e In Split(c.Offset(, 1).Value, ";")
n = n + 1
dic(n) = Array(c.Value, e)
Next
Next
With ws.Cells(5)
.CurrentRegion.ClearContents
.Resize(n, 2).Value = Application.Index(dic.items, 0, 0)
Set r = .CurrentRegion
End With
fn = Application.Index(r.Value, 1)
With ws.Cells(8)
.PivotTable.TableRange2.ClearContents
Set pvt = .Parent.Parent.PivotCaches.Create(xlDatabase, r).CreatePivotTable(.Cells)
End With
With pvt
.RowAxisLayout xlTabularRow
.ColumnGrand = False
.AddDataField .PivotFields(fn(2)), fn(2) & " ", xlCount
.AddFields PageFields:=fn(1), RowFields:=fn(2)
End With
End Sub
|
|