Sub ki276() Sheets("sheet1").Select ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ "Sheet1!R1C1:R27C4").CreatePivotTable TableDestination:=Range("G2"), _ TableName:="ピボットテーブル1" ActiveSheet.PivotTables("ピボットテーブル1").SmallGrid = False With ActiveSheet.PivotTables("ピボットテーブル1").PivotFields("日付") .Orientation = xlRowField .Position = 1 End With With ActiveSheet.PivotTables("ピボットテーブル1").PivotFields("製品") .Orientation = xlColumnField .Position = 1 End With With ActiveSheet.PivotTables("ピボットテーブル1").PivotFields("数量") .Orientation = xlDataField .Position = 1 End With Application.CommandBars("PivotTable").Visible = False Charts.Add ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("g3") ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1" Range("F1").Select ' 別シートへ表示 ' ActiveChart.Location Where:=xlLocationAsNewSheet ActiveSheet.ChartObjects.Select chmane = Selection.Name ActiveSheet.ChartObjects(chmane).Activate ActiveChart.ChartArea.Select ActiveSheet.Shapes(chmane).ScaleHeight 1.44, msoFalse, msoScaleFromTopLeft End Sub 'グラフ消去 Sub ki276a() Sheets("sheet1").Select Range("F1").Select shc = ActiveSheet.ChartObjects.Count If shc = 1 Then ActiveSheet.ChartObjects.Select Selection.Delete Else If shc > 1 Then MsgBox "図形が" & shc & "個あります手で消去してください" End If End If ActiveSheet.PivotTables("ピボットテーブル1").PivotSelect "", xlDataAndLabel Selection.ClearContents Range("G1").Select End Sub