XL 2016 Imbrication de conditions

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 !

KeepExploit

XLDnaute Nouveau
Bonjour a tous,

J'ai un fichier qui a de nombreuses procédures avec plein de GoTo, et je les refais au fur et a mesure car les appels commencent à être très long...

J'en ai une en particulier que je ne sais pas comment réécrire 🙁

VB:
Sub Macro61()
    Application.ScreenUpdating = False

    Sheets("ref pièces").Select

    doc = InputBox("Type du DOC?")
    num = InputBox("N° du DOC?")
    rev = InputBox("Rev du DOC?")
    
    Dim a As Integer, b As Integer
    
    a = 2
    b = 20


    Do While b < 33
    
line1:
    
        If Cells(a, 1) <> vbNullString Then
            If Cells(a, b) = vbNullString Then
                a = a + 1
                GoTo line1
            Else
                If Cells(a, 1) <> vbNullString Then
                    If Cells(a, b) = doc Then
                        If Cells(a, b + 1) = num Then
                            Cells(a, b + 2) = "'" & rev
                            a = a + 1
                            GoTo line1
                        Else
                            a = a + 1
                            GoTo line1
                        End If
                    Else
                        a = a + 1
                        GoTo line1
                    End If
                Else
                    a = a + 1
                    GoTo line1
                End If
            End If
        End If
        a = 2
        b = b + 5
    Loop

    a = 2
    b = 36

    Do While b < 49
    
line2:
        If Cells(a, 1) <> vbNullString Then
            If Cells(a, b) = vbNullString Then
                a = a + 1
                GoTo line2
            Else
                If Cells(a, 1) <> vbNullString Then
                    If Cells(a, b) = doc Then
                        If Cells(a, b + 1) = num Then
                            Cells(a, b + 2) = "'" & rev
                            a = a + 1
                            GoTo line2
                        Else
                            a = a + 1
                            GoTo line2
                        End If
                    Else
                        a = a + 1
                        GoTo line2
                    End If
                Else
                    a = a + 1
                    GoTo line2
                End If
            End If
        End If
        a = 2
        b = b + 5
    
    Loop

    Application.ScreenUpdating = True

End Sub
 
Bonjour KeepExploit,
Sans vouloir trop m'avancer et sans pouvoir le tester, j'ai l'impression que votre imbrication de IF de line1 peut se résumer ainsi :
VB:
    Do While b < 33
line1:
        Do While Cells(a, 1) <> vbNullString
            If Cells(a, b)="doc" And Cells(a, b + 1) = num Then
                Cells(a, b + 2) = "'" & rev
            End If
            a = a + 1
        Loop
        a = 2
        b = b + 5
    Loop
a = 2
b = 36
C'est à dire qu'on met rev si Cells(a,b) contient doc et Cells(a, b + 1) contient num
et on boucle tant que Cells(a, 1) n'est pas vide.
 
- 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 Problème de date
Réponses
5
Affichages
162
Réponses
4
Affichages
177
  • Question Question
XL 2021 VBA excel
Réponses
4
Affichages
169
Retour