[VBA] Graphique

Bonjour,

Je vous sollicite une nouvelle fois ^^

J'aimerais pouvoir réalisé un graphique avec VBA, mais je voudrais pourvoir avoir des variables à la place des valeurs de cellules, j'ai essayer le programme ci-dessous, mais j'ai une erreur 1004 qui s'affiche.

Private Sub CB_Tracer_les_graphiques_Click()
Dim Cellule_début As Range, Cellule_fin As Range, rgFeuille As Range, cellule_décalé_début As Range, cellule_décalé_fin As Range
Dim valeur_début As String, valeur_fin As String
Dim heured As String, heuref As String, nom_fichier As String
Dim valeur_décalé_début As String, valeur_décalé_fin As String
Dim i As Integer
i = 0
nom_fichier = Range("A1").Value
While i < nb_ana
    i = i + 1
    heured = Me.Controls("TB_d_" & i).Value
    heuref = Me.Controls("TB_f_" & i).Value
    Windows(nom_fichier & ".xlsx").Activate
    Set rgFeuille = Sheets(nom_fichier).UsedRange
    Set Cellule_début = rgFeuille.Find(what:=heured)
        If Cellule_début Is Nothing Then
        MsgBox "la valeur n'existe pas"
        Else
        valeur_début = Cellule_début.Address
        Set cellule_décalé_début = Cellule_début.Offset(, 3)
        valeur_décalé_début = cellule_décalé_début.Address
        End If
    Set rgFeuille = Sheets(nom_fichier).UsedRange
    Set Cellule_fin = rgFeuille.Find(what:=heuref)
        If Cellule_début Is Nothing Then
        MsgBox "la valeur n'existe pas"
        Else
        valeur_début = Cellule_fin.Address
        Set cellule_décalé_fin = Cellule_fin.Offset(, 3)
        valeur_décalé_fin = cellule_décalé_fin.Address
        End If
Wend
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveChart.SetSourceData Source:=Range("nom_fichier!$A$1")
ActiveChart.PlotArea.Select
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveChart.FullSeriesCollection(1).XValues = "=nom_fichier!Cellule_début.Address:Cellule_fin.Address"
ActiveChart.FullSeriesCollection(1).Values = "=nom_fichier!cellule_décalé_début.Address:cellule_décalé_fin.Address"

Merci par avance de votre aide.

Laurine

Bonjour

Tu devrais joindre ton fichier complet.

Bye !

Voilà le fichier

J'ai réussi à résoudre mon problème en modifiant mon code comme suit :

je suis passé de ça

ActiveChart.FullSeriesCollection(1).XValues = "=nom_fichier!Cellule_début.Address:Cellule_fin.Address"
ActiveChart.FullSeriesCollection(1).Values = "=nom_fichier!cellule_décalé_début.Address:cellule_décalé_fin.Address"

à ça :

ActiveChart.FullSeriesCollection(1).XValues = "=" & nom_fichier & "!" & valeur_début ":" & valeur_fin
ActiveChart.FullSeriesCollection(1).Values = "=" & nom_fichier & "!" & valeur_décalé_début & ":" & valeur_décalé_fin

Merci à vous d'avoir apporter de l'importance à mon problème.

Rechercher des sujets similaires à "vba graphique"