Fixer zone d'affichage de graphe

Bonjour

Merci déjà pour l'aide que vous voudrez bien m'apporter.

En gros, j'ai un code où l'utilisateur choisit la valeur de la variable Nombre et la macro doit tracer le graphe qui va avec. Le soucis c'est qu'il ne rafraichit pas l'affichage , il superpose les graphes des différentes valeurs de Nombre.

Exemple : on effectue un premier calcul , il trace le graphe (un peu n'importe où)

ensuite, si on fait un deuxième calcul, on aura les deux graphes sur la feuille.

J'aurais voulu n'obtenir sur la feuille que le graphe pour le paramètre Nombre en cours. Et surtout pouvoir définir une zone d'affichage unique pour le graphe pour ne pas qu'il l'affiche n'importe où

Sub Bouton2_QuandClic()

Nombre = Range("Nombre").Value

For j = 1 To Nombre

ThisWorkbook.Sheets("Feuil2").Cells(1,j) = 2*j

Next j

Dim maplage

Set maplage = ThisWorkbook.Sheets("feuil2").Range("A1").CurrentRegion

Charts.Add

With ActiveChart

.ChartType = xlLine

.SetSourceData Source:=maplage, PlotBy:=xlColumns

.Location Where:=xlLocationAsObject, Name:="Feuil1"

End With

End Sub

Bonsoir,

Une proposition à adapter.

Public Sub Créer_graphique()
Dim f1 As Worksheet, f2 As Worksheet
Dim Plage As Range
Dim shp As Shape
Dim i As Integer
    Application.ScreenUpdating = False
    Set f1 = Worksheets("Feuil1")
    Set f2 = Worksheets("Feuil2")
    On Error Resume Next
        f2.ChartObjects.Delete
    On Error GoTo 0
    With f1
        .Rows(3).Clear
        For i = 1 To .[B1]
            .Cells(3, i) = 2 * i
        Next i
        Set Plage = .[A3].CurrentRegion
        Set shp = f1.Shapes.AddChart
        With .Range("B2:G10")
            shp.Top = .Top
            shp.Left = .Left
            shp.Height = .Height
            shp.Width = .Width
        End With
        With shp
            .Name = "Graph_1"
            With .Chart
                .SetSourceData Source:=Plage, PlotBy:=xlRows
                .ChartType = xlLine
                .Location where:=xlLocationAsObject, Name:=f2.Name
            End With
        End With
    End With
    Set f1 = Nothing: Set Plage = Nothing: Set shp = Nothing
End Sub

Merci beaucoup

ça marche nickel

Rechercher des sujets similaires à "fixer zone affichage graphe"