Explication VBA, Décripter un code !

  • Initiateur de la discussion Initiateur de la discussion aude229
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

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:
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.

 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
274
Réponses
4
Affichages
367
Réponses
3
Affichages
607
  • Question Question
Microsoft 365 Export données
Réponses
4
Affichages
512
  • Question Question
XL 2021 VBA excel
Réponses
4
Affichages
89
  • Question Question
Microsoft 365 VBA Transpose
Réponses
11
Affichages
761
Réponses
0
Affichages
386
Réponses
2
Affichages
422
Retour