Hello,

Je voudrais créer un Graph à partir d'un TCD qui se trouve dans un Fichier Excel, et le mettre dans un autre fichier Excel

Voici mon Code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
  Sub createGraphALMTFailGainLossTCD()
 
    'declare object variables to hold references to worksheet, source data cell range, created bar chart, and destination cell range
    Dim myWorksheet As Worksheet
    Dim mySourceData As Range
    Dim myChart As Chart
    Dim myChartDestination As Range
    Dim wbkFrom As Workbook
    Dim Pvt As PivotTable
    Dim Count As Integer
 
    'identify worksheet containing source data and created bar chart
    Set wbkFrom = Workbooks("30-HI Long Extract -07102018.xlsm")
 
    Set Pvt = wbkFrom.Worksheets("Graph ALMT Fail Gain Loss").PivotTables("PivotTable4")
    Count = Pvt.TableRange2.Rows.Count
    Set myWorksheet = wbkFrom.Worksheets("Graph ALMT Fail Gain Loss")
    With myWorksheet
 
        'identify source data
        Set mySourceData = .Range("L6:" & "Count")
        'ActiveSheet.PivotTables("PivotTable4").PivotSelect "", xlDataAndLabel, True
 
    End With
 
    Set myWorksheet = ThisWorkbook.Worksheets("Dashboard")
 
    With myWorksheet
 
        'identify chart location
        Set myChartDestination = .Range("A37:F55")
 
        'create bar chart
        Set myChart = .Shapes.AddChart2(Style:=-1, XlChartType:=xlColumnClustered, Left:=myChartDestination.Cells(1).Left, Top:=myChartDestination.Cells(1).Top, Width:=myChartDestination.Width, Height:=myChartDestination.Height, NewLayout:=False).Chart
        myChart.Rotation = 90#
 
    End With
 
    'set source data for created bar chart
    myChart.SetSourceData Source:=mySourceData
 
End Sub