XL 2016 Imbrication de conditions

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
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
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.
 

Discussions similaires

Réponses
5
Affichages
405

Membres actuellement en ligne

Aucun membre en ligne actuellement.

Statistiques des forums

Discussions
314 022
Messages
2 104 732
Membres
109 116
dernier inscrit
RALAIZANAKA