code erroné ?

netten

XLDnaute Junior
Bonjour à toutes et tous,

J'ai ce code ci-dessous et vba m'annonce un code 400, d'une part, est-ce que ces lignes vous paraissent corectes ? et d'autre part est-ce que l'erreur 400 est justifiée ?

Il me semble que l'erreur 400 concerne la msgbox

Code:
Sub Nouvelorgane()

Select Case MsgBox("Souhaitez vous rajouter un organe ?", vbOKCancel, "Validation")
Case vbOK

Dim col1 As Byte 'déclare la variable col1 (COLonne)
Dim col2 As Byte 'déclare la variable col2 (COLonne)
Dim col3 As Byte 'déclare la variable col3 (COLonne)
Dim col4 As Byte 'déclare la variable col4 (COLonne)
Dim col5 As Byte 'déclare la variable col5 (COLonne)
Dim col6 As Byte 'déclare la variable col6 (COLonne)


col1 = Rows(1633).Find(Range("IM29").Value, , xlValues, xlWhole).Column
        Cells(1644, col).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
        Range("IL25").ClearContents

        col2 = Rows(1648).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                Cells(1659, col).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                Range("IL25").ClearContents
                
                col3 = Rows(1663).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                        Cells(1674, col).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                        Range("IL25").ClearContents

                        col4 = Rows(1678).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                                Cells(1689, col).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                Range("IL25").ClearContents

                               col5 = Rows(1693).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                                        Cells(1704, col).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                        Range("IL25").ClearContents
 
                                         col6 = Rows(1709).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                                                Cells(1720, col).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                                Range("IL25").ClearContents

Case vbCancel

Range("IL25").Select

End Select

End Sub

Je vous remercie beaucoup de votre coup d'oeil sur la question, bien cordialement, Eric :)
 

Odesta

XLDnaute Impliqué
Re : code erroné ?

Bonjour

Code:
 Cells(1644, col).

col n'est pas déclarée et pas initiée. donc Cells(1644, col) va créer une erreur.

je n'ai pas testé la suite, mais c'est déjà un pb à résoudre.

Cdt
Olivier

EDIT : L'erreur 400 concernerait un autre problème, lié à l'userfom ou à la feuille. Je ne maitrise pas assez pour en parler sans fichier exemple "buggé".
 
Dernière édition:

netten

XLDnaute Junior
Re : code erroné ?

J'ai déjà modifier ce point, merci, mais ça ne marche que pour la première ligne (col1), les autres variables ne fonctionnent pas col2,3,...,6.
Je pense qu'il y a une façon d'agencer mes différentes variables pour qu'elles soient toutes pris en compte.


Code:
Sub Nouvelorgane()

Select Case MsgBox("Souhaitez vous rajouter un organe ?", vbOKCancel, "Validation")
Case vbOK

Dim col1 As Byte 'déclare la variable col1 (COLonne)
Dim col2 As Byte 'déclare la variable col2 (COLonne)
Dim col3 As Byte 'déclare la variable col3 (COLonne)
Dim col4 As Byte 'déclare la variable col4 (COLonne)
Dim col5 As Byte 'déclare la variable col5 (COLonne)
Dim col6 As Byte 'déclare la variable col6 (COLonne)


col1 = Rows(1633).Find(Range("IM29").Value, , xlValues, xlWhole).Column
        Cells(1644, col1).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
        Range("IL25").ClearContents

        col2 = Rows(1648).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                Cells(1659, col2).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                Range("IL25").ClearContents
                
                col3 = Rows(1663).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                        Cells(1674, col3).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                        Range("IL25").ClearContents

                        col4 = Rows(1678).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                                Cells(1689, col4).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                Range("IL25").ClearContents

                               col5 = Rows(1693).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                                        Cells(1704, col5).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                        Range("IL25").ClearContents
 
                                         col6 = Rows(1709).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                                                Cells(1720, col6).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                                Range("IL25").ClearContents



Case vbCancel

Range("IL25").Select

End Select

End Sub


Merci de votre aide :)
 

Pierrot93

XLDnaute Barbatruc
Re : code erroné ?

Bonjour à tous,

peut être une piste en procèdant ainsi :
Code:
Dim col1 As Range 'déclare la variable col1 (COLonne)

Set col1 = Rows(1633).Find(Range("IM29").Value, , xlValues, xlWhole)
If Not col1 Is Nothing Then
    Cells(1644, col1.Column).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
    Range("IL25").ClearContents
End If
bonne fin d'après midi
@+
 

Odesta

XLDnaute Impliqué
Re : code erroné ?

Bonjour

Il faut suivr ele conseil de Pierrot et utiliser un SET

L'instruction :
col2 = Rows(1648).Find(Range("IM29").Value, , xlValues, xlWhole).Column
n'est correcte que si la valeur est trouvée, hors justement, il arrive qu'elle ne le soit pas.

Si vous adaptez le morceau de Code de Pierrot, en prennant bien compte du "Set" puis du test, vous devrier obtenir ce que vous souhaitez.

Olivier
 

netten

XLDnaute Junior
Re : code erroné ?

Bonjour tout le monde,

j'ai pas encore réussi à faire fonctionner ce code, pour la raison que je ne voit pas comment dissocier correctement mes variables. Donc j'ai déjà fait un essai en utilisant la premire variable : col1, ça marche très bien, dès que j'e, mets une deuxième (j'enlève les '), marche plus.

Voilà mon code pour le moment :

Code:
Sub Nouvelorgane()

Select Case MsgBox("Souhaitez vous rajouter un organe ?", vbOKCancel, "Validation")
Case vbOK

Dim col1 As Range, col2 As Range, col3 As Range, col4 As Range, col5 As Range, col6 As Range


Set col1 = Rows(1633).Find(Range("IM29").Value, , xlValues, xlWhole)
If Not col1 Is Nothing Then
    Cells(1644, col1.Column).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
    Range("IL25").ClearContents
    

           '     Set col2 = Rows(1648).Find(Range("IM29").Value, , xlValues, xlWhole).Column
            '    If Not col1 Is Nothing Then
             '   Cells(1659, col2).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
              '  Range("IL25").ClearContents
               ' End If
                
           '     Set col3 = Rows(1663).Find(Range("IM29").Value, , xlValues, xlWhole).Column
            '    If Not col2 Is Nothing Then
             '           Cells(1674, col3).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
              '          Range("IL25").ClearContents
               '         End If

End If

Case vbCancel

Range("IL25").Select

End Select

End Sub



merci à vous tous ;)
 

Pierrot93

XLDnaute Barbatruc
Re : code erroné ?

Bonjour,

pour col2, modifie ainsi :
Code:
Set col2 = Rows(1648).Find(Range("IM29").Value, , xlValues, xlWhole)'       A ENLEVER        .Column
            '    If Not [B][COLOR="Red"]col2 [/COLOR][/B]Is Nothing Then
             '   Cells(1659, col2[COLOR="red"][B].Column[/B][/COLOR]).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
              '  Range("IL25").ClearContents
               ' End If
bonne journée
@+
 

netten

XLDnaute Junior
Re : code erroné ?

Code modifié de nouveau au niveau des If not col"x" is nothing then.

Le code ne donne pas d'erreur, mais le déplcament de la cellule ne s'est pas fait, je cherche l'erreurc :confused:


Code:
Sub Nouvelorgane()

Select Case MsgBox("Souhaitez vous rajouter un organe ?", vbOKCancel, "Validation")
Case vbOK

Dim col1 As Range, col2 As Range, col3 As Range, col4 As Range, col5 As Range, col6 As Range


Set [B]col1[/B] = Rows(1633).Find(Range("IM29").Value, , xlValues, xlWhole)
    If Not [B]col1[/B] Is Nothing Then
    Cells(1644, col1.Column).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
    Range("IL25").ClearContents
    

            Set [B]col2 [/B]= Rows(1648).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                If Not [B]col2[/B] Is Nothing Then
                Cells(1659, col2).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                Range("IL25").ClearContents
                End If
                
                    Set [B]col3[/B] = Rows(1663).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                        If Not [B]col3[/B] Is Nothing Then
                        Cells(1674, col3).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                        Range("IL25").ClearContents
                        End If

                            Set[B] col4 [/B]= Rows(1678).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                                If Not [B]col4[/B] Is Nothing Then
                                Cells(1689, col4).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                Range("IL25").ClearContents
                                End If

                                Set [B]col5[/B] = Rows(1693).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                                        If Not [B]col5[/B] Is Nothing Then
                                        Cells(1704, col5).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                        Range("IL25").ClearContents
                                        End If
 
                                        Set [B]col6[/B] = Rows(1709).Find(Range("IM29").Value, , xlValues, xlWhole).Column
                                                If Not [B]col6[/B] Is Nothing Then
                                                Cells(1720, col6).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                                Range("IL25").ClearContents
                                                End If


End If

Case vbCancel

Range("IL25").Select

End Select

End Sub
 

netten

XLDnaute Junior
Re : code erroné ?

Bonjour Pierrot et merci de ton aide,

oui, je viens de voir, voilà mon code avec tes modifications, ça ne déplace pas la donnée, elle reste sur place, la msgbox marxhe bien par contre. :D

Code:
Sub Nouvelorgane()

Select Case MsgBox("Souhaitez vous rajouter un organe ?", vbOKCancel, "Validation")
Case vbOK

Dim [COLOR="Red"]col1[/COLOR] As Range, [COLOR="red"]col2[/COLOR] As Range, [COLOR="red"]col3[/COLOR] As Range, [COLOR="red"]col4[/COLOR] As Range, [COLOR="red"]col5[/COLOR] As Range, [COLOR="red"]col6[/COLOR] As Range


Set [COLOR="red"]col1 [/COLOR]= Rows(1633).Find(Range("IM29").Value, , xlValues, xlWhole) '
    If Not [COLOR="red"]col1[/COLOR] Is Nothing Then
    Cells(1644, [COLOR="red"]col1.Column[/COLOR]).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
    Range("IL25").ClearContents
    

            Set [COLOR="red"]col2 [/COLOR]= Rows(1648).Find(Range("IM29").Value, , xlValues, xlWhole) '
                If Not [COLOR="red"]col2[/COLOR] Is Nothing Then
                Cells(1659, [COLOR="red"]col2.Column[/COLOR]).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                Range("IL25").ClearContents
                End If
                
                    Set [COLOR="red"]col3[/COLOR] = Rows(1663).Find(Range("IM29").Value, , xlValues, xlWhole) '
                        If Not [COLOR="red"]col3[/COLOR] Is Nothing Then
                        Cells(1674,[COLOR="red"] col3.Column[/COLOR]).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                        Range("IL25").ClearContents
                        End If

                            Set [COLOR="red"]col4[/COLOR] = Rows(1678).Find(Range("IM29").Value, , xlValues, xlWhole) '
                                If Not [COLOR="red"]col4[/COLOR] Is Nothing Then
                                Cells(1689, [COLOR="red"]col4.Column[/COLOR]).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                Range("IL25").ClearContents
                                End If

                                Set [COLOR="red"]col5[/COLOR] = Rows(1693).Find(Range("IM29").Value, , xlValues, xlWhole) '
                                        If Not [COLOR="red"]col5[/COLOR] Is Nothing Then
                                        Cells(1704, [COLOR="red"]col5.Column[/COLOR]).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                        Range("IL25").ClearContents
                                        End If
 
                                        Set [COLOR="red"]col6 [/COLOR]= Rows(1709).Find(Range("IM29").Value, , xlValues, xlWhole) '
                                                If Not [COLOR="red"]col6 [/COLOR]Is Nothing Then
                                                Cells(1720, [COLOR="red"]col6.Column[/COLOR]).End(xlUp).Offset(1, 0).Value = Range("IL25").Value
                                                Range("IL25").ClearContents
                                                End If


End If

Case vbCancel

Range("IL25").Select

End Select

End Sub
 
Dernière édition:

Discussions similaires

Réponses
2
Affichages
176

Statistiques des forums

Discussions
312 493
Messages
2 088 956
Membres
103 990
dernier inscrit
lamiadebz