Explication VBA, Décripter un code !

aude229

XLDnaute Nouveau
Bonjour,

Je suis casiement au terme de mon programme, mais il me reste quelques erreurs, dans un code et je ne comprend pas trop ce qu'il veut dire (il à été écrit par une personne qui travaillais sur ce programme avant). Je voudrais savoir si vous voyer à première vu des errreurs ou tous simplement ce à quoi renvoi ce code.

Code:
Private Sub UserForm_Activate()

an = Range("ANNEEDEP")
ANNEE.Caption = an & ", " & an - 1 & ", " & an - 2
ANNEE2.Caption = an - 1 & ", " & an - 2 & ", " & an - 3

End Sub
Private Sub CommandButton1_Click()

Unload Me

Application.ScreenUpdating = False

If Month(Sheets("Menu").Range("C1")) - 1 = 0 Then
mois = 1
Else: mois = Month(Sheets("Menu").Range("C1")) - 1
End If

If Sheets("Paramètres").Range("CodeA") = 0 Then
    NBgraph = 0
    ElseIf Sheets("Paramètres").Range("CodeB") = 0 Then
        NBgraph = 1
        ElseIf Sheets("Paramètres").Range("CodeC") = 0 Then
            NBgraph = 2
            ElseIf Sheets("Paramètres").Range("CodeD") = 0 Then
                NBgraph = 3
                ElseIf Sheets("Paramètres").Range("CodeE") = 0 Then
                    NBgraph = 4
                    ElseIf Sheets("Paramètres").Range("CodeF") = 0 Then
                        NBgraph = 5
                        ElseIf Sheets("Paramètres").Range("CodeG") = 0 Then
                            NBgraph = 6
                            ElseIf Sheets("Paramètres").Range("CodeH") = 0 Then
                                NBgraph = 7
                                ElseIf Sheets("Paramètres").Range("CodeI") = 0 Then
                                    NBgraph = 8
                                    ElseIf Sheets("Paramètres").Range("CodeJ") = 0 Then
                                        NBgraph = 9
                                        ElseIf Sheets("Paramètres").Range("CodeK") = 0 Then
                                            NBgraph = 10
                                            ElseIf Sheets("Paramètres").Range("CodeL") = 0 Then
                                                NBgraph = 11
                                                ElseIf Sheets("Paramètres").Range("CodeM") = 0 Then
                                                    NBgraph = 12
                                                    ElseIf Sheets("Paramètres").Range("CodeN") = 0 Then
                                                        NBgraph = 13
                                                        ElseIf Sheets("Paramètres").Range("CodeO") = 0 Then
                                                            NBgraph = 14
                                                            Else: NBgraph = 15
                                        
                                        
End If

If ANNEE = True Then
    Sheets("Graphiques").Range("ANGRAPH") = Sheets("TAB").Range("ANNEEDEP")

    i = 1
    j = 2
    Do

'' [COLOR="#FF0000"]Le code bloque à partir de là[/COLOR]''
    Sheets("Graphiques").ChartObjects("Graphique " & i).Activate 
    ActiveChart.SeriesCollection(1).Values = "=TAB!R" & j & "C7:R" & j + 11 & "C7"
    ActiveChart.SeriesCollection(1).Name = "=TAB!R1C7"
    ActiveChart.SeriesCollection(2).Values = "=TAB!R" & j & "C5:R" & j + 11 & "C5"
    ActiveChart.SeriesCollection(2).Name = "=TAB!R1C5"
    ActiveChart.SeriesCollection(3).Values = "=TAB!R" & j & "C3:R" & j + 11 & "C3"
    ActiveChart.SeriesCollection(3).Name = "=TAB!R1C3"
    ActiveChart.SeriesCollection(3).ApplyDataLabels AutoText:=True, ShowValue:=False
    ActiveChart.SeriesCollection(3).Points(mois).ApplyDataLabels AutoText:=True, ShowValue:=True
    With ActiveChart.SeriesCollection(3).DataLabels.Border
        .Weight = 1
        .LineStyle = -4105
    End With
    ActiveChart.SeriesCollection(3).DataLabels.Shadow = True
    ActiveChart.SeriesCollection(3).DataLabels.Interior.ColorIndex = -4105
    With ActiveChart.SeriesCollection(3).DataLabels.Font
        .Name = "Arial"
        .FontStyle = "Gras italique"
        .Size = 10
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
        .Background = xlAutomatic
    End With

    i = i + 1
    j = j + 12
    Loop While (i < NBgraph + 1)
    
    Else
    Sheets("Graphiques").Range("ANGRAPH") = Sheets("TAB").Range("ANNEEDEP") - 1
 
    i = 1
    j = 2
    Do
    Sheets("Graphiques").ChartObjects("Graphique " & i).ChartObjects.Activate
    ActiveChart.SeriesCollection(1).Values = "=TAB!R" & j & "C9:R" & j + 11 & "C9"
    ActiveChart.SeriesCollection(1).Name = "=TAB!R1C9"
    ActiveChart.SeriesCollection(2).Values = "=TAB!R" & j & "C7:R" & j + 11 & "C7"
    ActiveChart.SeriesCollection(2).Name = "=TAB!R1C7"
    ActiveChart.SeriesCollection(3).Values = "=TAB!R" & j & "C5:R" & j + 11 & "C5"
    ActiveChart.SeriesCollection(3).Name = "=TAB!R1C5"
    ActiveChart.SeriesCollection(3).ApplyDataLabels AutoText:=True, ShowValue:=False
    ActiveChart.SeriesCollection(3).Points(12).ApplyDataLabels AutoText:=True, ShowValue:=True
    With ActiveChart.SeriesCollection(3).DataLabels.Border
        .Weight = 1
        .LineStyle = -4105
    End With
    ActiveChart.SeriesCollection(3).DataLabels.Shadow = True
    ActiveChart.SeriesCollection(3).DataLabels.Interior.ColorIndex = -4105
    With ActiveChart.SeriesCollection(3).DataLabels.Font
        .Name = "Arial"
        .FontStyle = "Gras italique"
        .Size = 10
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
        .Background = xlAutomatic
    End With
    
    
    i = i + 1
    j = j + 12
    Loop While (i < NBgraph + 1)
    End If
Application.ScreenUpdating = True
Sheets("Graphiques").Range("ANGRAPH").Select
End Sub

Merci d'avance pour votre aide !
 
Dernière édition:

chris

XLDnaute Barbatruc
Re : Explication VBA, Décripter un code !

Bonjour

Hors contexte...

Ce code analyse des plages nommées CodeA à CodeL, ANNEEDEP,ANGRAPH et en utilise les informations pour réaliser un graphique.

Il n'est pas optimisé (un select case serait plus adéquat que cette collection de elseif) mais hors contexte impossible de dire s'il fonctionne ou non.

Il est déclenché par le bouton d'un userform semble-t-il.

 

Discussions similaires

Réponses
11
Affichages
292
Réponses
0
Affichages
153

Statistiques des forums

Discussions
312 215
Messages
2 086 329
Membres
103 182
dernier inscrit
moutassim.amine