IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Remove item qui ne fonctionne pas à tout les coups ?


Sujet :

Macros et VBA Excel

  1. #1
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Juillet 2011
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2011
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Remove item qui ne fonctionne pas à tout les coups ?
    Bonjour à tous !

    J'ai un classeur qui me génère automatiquement une feuille pour chaque nouveau projet que j'ajoute. Pour chaque projet j'ai un commandbutton qui lance un userform me permettant à l'aide de combobox d'aller chercher dans un tableau base de donnée une référence.
    Tout fonctionne sauf que pour certaine référence il me "error 424 objet requis" sur cette ligne :
    ComboBox2.List.RemoveItem b

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    Private Sub CB_Type_Ok_Click()
    Dim i, j, k As Integer
    Dim Var_T As String
    Dim Var_CBB As String
    Dim Var_B   As Boolean
    Dim Var_Vlist As String
    Dim Var_Item As String
    Dim Var_Vlist2 As String
    Dim Var_B2, Var_B3 As Boolean
    Dim a As Integer
    Dim b As Integer
    Dim c As Integer
    Dim Var_Test1 As String
    Dim Var_Test3 As String
    Dim Var_Test2 As String
     
     
    'Filtrage donnée en fonction de la valeur de la liste
     
    Var_T = ComboBox1.Value
    Var_B = False
    Var_Item = "*"
    Var_B2 = False
     
     
    'If Var_T = "*" Then
     
    'Else
     
    'End If
     
     
    'Activation recherche fournisseur
    ComboBox2.Enabled = True
    CB_F_Ok.Enabled = True
    ComboBox1.Enabled = False
    CB_Type_Ok.Enabled = False
    ComboBox2.AddItem Var_Item
     
     
     
     
     
     
         Var_Vlist = ComboBox1.List(ComboBox1.ListIndex)
     
     
        If Var_Vlist = Var_T Then
     
               For i = 2 To 397
                        Var_CBB = Sheets("BDD Dési").Range("C" & i).Value
                       Var_Vlist2 = Sheets("BDD Dési").Range("B" & i).Value
     
     
                           'Test pour savoir si la ligne correspond bien à la sélection type
     
                           If Var_Vlist2 = Var_Vlist Then
                               For j = 0 To ComboBox2.ListCount - 1
     
                                ComboBox2.ListIndex = j
                                 If ComboBox2.Value = Var_CBB Then
                                        Var_B2 = True
                                        Else
                                        Var_B2 = False
                                    End If
     
     
     
     
                                Next j
                                If Var_B2 = False Then
                                    ComboBox2.AddItem Var_CBB
                                    Else
     
                                    End If
                               Else
     
                           End If
               Next i
     
               ' test de présence doublon
     
                For a = 0 To ComboBox2.ListCount
                            ComboBox2.ListIndex = a
                            Var_Test1 = ComboBox2.Value
                            c = a + 1
                            If c >= ComboBox2.ListCount Then
                            Exit Sub
                            Else
                            End If
     
                            ComboBox2.ListIndex = c
                            Var_Test3 = ComboBox2.Value
     
                          If Var_Test1 = Var_Test3 Then
                          Var_B3 = True
                          Else: Var_B3 = False
                          End If
     
                          If Var_B3 = False Then
     
     
                            For b = 0 To ComboBox2.ListCount - 1
                                If b > ComboBox2.ListCount - 1 Then
                                Exit For
                                Else: End If
     
                                ComboBox2.ListIndex = b
                                Var_Test2 = ComboBox2.Value
     
                                If Var_Test1 = Var_Test2 Then
                                ComboBox2.List.RemoveItem b
     
     
                                Else
                                End If
     
                            Next b
                          Else
                          End If
                        Next a
           Else
           End If
     
     
     
    End Sub

  2. #2
    Membre émérite
    Homme Profil pro
    Inscrit en
    Décembre 2011
    Messages
    1 186
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2011
    Messages : 1 186
    Points : 2 502
    Points
    2 502
    Par défaut
    Bonsoir,

    Essaye de remplacer ComboBox2.List.RemoveItem b par ComboBox2.RemoveItem b

Discussions similaires

  1. TRegistry qui ne fonctionne pas à tout les coups
    Par davels dans le forum Composants VCL
    Réponses: 6
    Dernier message: 06/05/2011, 02h00
  2. Réponses: 2
    Dernier message: 16/03/2010, 09h49
  3. Réponses: 4
    Dernier message: 04/11/2009, 22h31
  4. _POST qui ne fonctionne pas tout le temps
    Par johnson95 dans le forum Langage
    Réponses: 8
    Dernier message: 24/04/2008, 09h45
  5. Réponses: 10
    Dernier message: 13/03/2007, 11h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo