Vb sous excel

Bonjour,

je suis entrain de monter une application vb sous excel qui permet de comparer plusieurs bases de données avec une base de donnée et là pour comparer la base de donnée berrechid j'ai utilisé ce programme, à chaque fois qu'il y a un vide je veux recuperer tte la ligne de la base de donnée mais le programme ne marche pas, SVP je veux savoir pourquoi le programme ci dessus ne marche pas ???

' programme de comparaison pour B3
For i = 5 To 500

If Feuil74.Cells(i, 1) = Feuil74.Cells(i, 7) Then
Feuil74.Cells(i, 13) = "VRAI"
Else
Feuil74.Cells(i, 13) = "FAUX"

If Feuil74.Cells(i, 7) = "" Then

j = 5

GoTo label

Else

If Feuil74.Cells(i, 1) = "" Then

j = 5

GoTo label2

End If

End If
End If
Next i

label: For m = 7 To 500

Feuil74.Cells(j, 32) = Feuil13.Cells(m, 1)
Feuil74.Cells(j, 33) = Feuil13.Cells(m, 2)
Feuil74.Cells(j, 34) = Feuil13.Cells(m, 3)
Feuil74.Cells(j, 35) = Feuil13.Cells(m, 4)
Feuil74.Cells(j, 36) = Feuil13.Cells(m, 5)
Feuil74.Cells(j, 37) = Feuil13.Cells(m, 6)
Feuil74.Cells(j, 38) = Feuil13.Cells(m, 7)
Feuil74.Cells(j, 39) = Feuil13.Cells(m, 8)
Feuil74.Cells(j, 40) = Feuil13.Cells(m, 9)
Feuil74.Cells(j, 41) = Feuil13.Cells(m, 10)
Feuil74.Cells(j, 42) = Feuil13.Cells(m, 11)
Feuil74.Cells(j, 43) = Feuil13.Cells(m, 12)
Feuil74.Cells(j, 44) = Feuil13.Cells(m, 13)
Feuil74.Cells(j, 45) = Feuil13.Cells(m, 14)
Feuil74.Cells(j, 46) = Feuil13.Cells(m, 15)
Feuil74.Cells(j, 47) = Feuil13.Cells(m, 16)
Feuil74.Cells(j, 48) = Feuil13.Cells(m, 17)
j = j + 1

Next m

label2: For k = 3 To 28133

If Feuil4.Cells(k, 1) = "BERCHID1" Then

Feuil74.Cells(j, 19) = Feuil4.Cells(k, 1)
Feuil74.Cells(j, 20) = Feuil4.Cells(k, 2)
Feuil74.Cells(j, 21) = Feuil4.Cells(k, 3)
Feuil74.Cells(j, 22) = Feuil4.Cells(k, 4)
j = j + 1

End If
Next k
Configuration: Windows XP
Firefox 2.0.0.16

3 réponses

  1. Bonjour,

    Suggestion de modification pour meilleur compréhension :

    Option Explicit
    
    Sub Test()
    
        Dim I As Integer, K As Integer
        
    
        For I = 5 To 500
            If Feuil74.Cells(I, 1) = Feuil74.Cells(I, 7) Then
                Feuil74.Cells(I, 13) = "VRAI"
            Else
                Feuil74.Cells(I, 13) = "FAUX"
                If Feuil74.Cells(I, 7) = "" Then
                    Call Boucle1(5)
                Else
                    If Feuil74.Cells(I, 1) = "" Then
                        Call Boucle2(5)
                    End If
                End If
            End If
        Next I
    
    End Sub
    
    Sub Boucle1(ByRef J As Integer)
        
        Dim Compteur1 As Integer, Compteur2 As Integer
        
        Compteur1 = 32: Compteur2 = 1
        For m = 7 To 500
            Feuil74.Cells(J, Compteur1) = Feuil13.Cells(m, Compteur2)
            J = J + 1: Compteur1 = (Compteur1 + 1): Compteur2 = (Compteur2 + 1)
        Next m
    End Sub
    '
    
    Sub Boucle2(ByRef J As Integer)
    
        Dim Compteur1 As Integer, Compteur2 As Integer
    
        Compteur1 = 19: Compteur2 = 1
        For K = 3 To 28133
            If Feuil4.Cells(K, 1) = "BERCHID1" Then
                Feuil74.Cells(J, Compteur1) = Feuil4.Cells(K, Compteur2)
                J = J + 1: Compteur1 = (Compteur1 + 1): Compteur2 = (Compteur2 + 1)
            End If
        Next K
    
    End Sub
    '
    


    Conseil : Éviter les Goto Label, reformuler la structure dans ces cas !

    Lupin

    1. une erreur qui s'affiche au niveau de la ligne : Feuil74.Cells(s, Compteur1) = Feuil13.Cells(m, Compteur2)

      j'ai effectué des changements de variables parce que le programme comporte plusieurs comparaisons
      voilà le programme que j'ai mis :

      ' programme de comparaison pour B3

      Dim h As Integer, p As Integer, s As Integer, m As Integer

      For h = 5 To 500
      If Feuil74.Cells(h, 1) = Feuil74.Cells(h, 7) Then
      Feuil74.Cells(h, 13) = "VRAI"
      Else
      Feuil74.Cells(h, 13) = "FAUX"
      If Feuil74.Cells(h, 7) = "" Then
      Call Boucle1(5)
      Else
      If Feuil74.Cells(h, 1) = "" Then
      Call Boucle2(5)
      End If
      End If
      End If
      Next h

      End Sub

      Sub Boucle1(ByRef s As Integer)

      Dim Compteur1 As Integer, Compteur2 As Integer

      Compteur1 = 32: Compteur2 = 1
      For m = 7 To 500
      Feuil74.Cells(s, Compteur1) = Feuil13.Cells(m, Compteur2)
      s = s + 1: Compteur1 = (Compteur1 + 1): Compteur2 = (Compteur2 + 1)
      Next m
      End Sub
      '

      Sub Boucle2(ByRef J As Integer)

      Dim Compteur1 As Integer, Compteur2 As Integer

      Compteur1 = 19: Compteur2 = 1
      For p = 3 To 28133
      If Feuil4.Cells(p, 1) = "BERCHID1" Then
      Feuil74.Cells(s, Compteur1) = Feuil4.Cells(p, Compteur2)
      s = s + 1: Compteur1 = (Compteur1 + 1): Compteur2 = (Compteur2 + 1)
      End If
      Next p
      End Sub

      Merci.

      1. re :

        La structure me semble bonne, j'ai apporté quelques petites modifications,
        mais l'déal est de tester en mode pas a pas pour trouver l'erreur.

        J'imagine qu'il s'agit d'une erreur de débordement (1004) ?
        Je n'ai pas trouver de balayage supérieur à 32768 mais par
        précaution j'ai converti tous les type en [ Long ].

        Option Explicit
        
        Sub Essai()
        
            ' Dans la routine principal, seul la variable
            ' h a besoin d'être défini en local
            Dim h As Long
        
            For h = 5 To 500
                If Feuil74.Cells(h, 1) = Feuil74.Cells(h, 7) Then
                    Feuil74.Cells(h, 13) = "VRAI"
                Else
                    Feuil74.Cells(h, 13) = "FAUX"
                    If Feuil74.Cells(h, 7) = "" Then
                        Call Boucle1(5)
                    Else
                        If Feuil74.Cells(h, 1) = "" Then
                            Call Boucle2(5)
                        End If
                    End If
                End If
            Next h
        
        End Sub
        '
        
        Sub Boucle1(ByVal s As Long)
        ' Ici, s est déclaré à l'intérieur de la déclaration
        ' de la sous-routine et puisque qu'il n'est pas utilisé
        ' en retour, j'ai modifié pour ByVal
        
            Dim M As Long, Compteur1 As Long, Compteur2 As Long
        
            Compteur1 = 32: Compteur2 = 1
            For M = 7 To 500
                Feuil74.Cells(s, Compteur1) = Feuil13.Cells(M, Compteur2)
                s = s + 1: Compteur1 = (Compteur1 + 1): Compteur2 = (Compteur2 + 1)
            Next M
            
        End Sub
        '
        
        Sub Boucle2(ByVal J As Long)
        ' Ici, J est déclaré à l'intérieur de la déclaration
        ' de la sous-routine et puisque qu'il n'est pas utilisé
        ' en retour, j'ai modifié pour ByVal
        
            Dim P As Long, Compteur1 As Long, Compteur2 As Long
        
            Compteur1 = 19: Compteur2 = 1
            For P = 3 To 28133
                If Feuil4.Cells(P, 1) = "BERCHID1" Then
                    Feuil74.Cells(s, Compteur1) = Feuil4.Cells(P, Compteur2)
                    s = s + 1: Compteur1 = (Compteur1 + 1): Compteur2 = (Compteur2 + 1)
                End If
            Next P
            
        End Sub
        '
        

        Lupin