-
Notifications
You must be signed in to change notification settings - Fork 0
/
pt-pc.vb
56 lines (42 loc) · 1.31 KB
/
pt-pc.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Option Explicit
Sub BuatPT()
Dim pc As PivotCache
Dim pt As PivotTable
Dim pf As PivotField
Dim ws As Worksheet
Dim wsg As Integer
Dim i As Integer
wsg = Worksheets.Count
For i = wsg To 2 Step -1
Set pc = ThisWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:="'" & Worksheets(i).Name & "'!" & Worksheets(i).Range("A1").CurrentRegion.Address(ReferenceStyle:=xlR1C1))
Set ws = Worksheets.Add(After:=Worksheets(Worksheets.Count))
ws.Name = "day" & i - 1
Range("A5").Select
Set pt = pc.CreatePivotTable( _
TableDestination:=ActiveCell, _
TableName:="Day" & i - 1)
pt.AddFields _
RowFields:="Start Time", _
ColumnFields:="Col1", _
PageFields:=Array("Col2", "Col3", "Col4", "Col5")
pt.AddDataField pt.PivotFields("Col6"), , xlAverage
Next i
End Sub
Sub buatChart()
Dim sh As Shape
Dim wsc As Worksheet
Dim ch As Chart
'Set wsc = Worksheets("day1")
For Each wsc In Worksheets
If wsc.Name Like "day*" Then
Set sh = wsc.Shapes.AddChart2( _
XlChartType:=XlChartType.xlLineMarkers, _
Left:=300, Top:=70, Width:=500, Height:=300)
Set ch = sh.Chart
ch.ClearToMatchStyle
ch.ChartStyle = 233
End If
Next
End Sub