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 :

Erreur d'exécution 91: Variable objet ou variable de bloc With non définie.


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Juin 2014
    Messages : 16
    Par défaut Erreur d'exécution 91: Variable objet ou variable de bloc With non définie.
    Bonjour,

    J’arrive pas à résoudre mon problème depuis deux jours, je ne retrouvais plus le rubrique pour publier, je me suis bloquer sur une macro simple, j’ai un tableau avec des colonnes et sur 3 Colonnes S T U à partir de la ligne 8 de mon tableau j’ai des ok et Nok, je voulais copier (source) et coller (destination) sur une autre feuille du meme fichier ou d'un autre fichier du même dossier, si c’est NOK , mais pas la ligne entière juste quelques cellules de la ligne et ainsi de suite jusqu'à la dernière ligne non vide, j’arrive pas lui dire de passer à la ligne suivante et aussi de coller sur l’autre feuille destination au niveau de la dernière ligne vide les quelques cellules que je vais copier. ainsi faire un boucle pour recommencer l'exercice

    J’ai fait une macro mais trop d’erreurs, j’aimerai vraiment de l’aide, des explications si possible

    Cordialement
    Papis

    Si vous aviez besoin du fichier je le mettrais

    mon code :

    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
    Sub MacroCopieCellIfNOk()
     
    Dim x As Variant
     
    Dim LastRow As Long
    Dim WsDepart As Worksheet
    Dim WsDestination As Worksheet
     
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
     
     
        Set WsDestination = SHEETS("Lup")
        Set WsDepart = SHEETS("Developpement")
     
     
        ' Cela suppose que la colonne S soit remplie
        '   avec qqs données sinon à adapter à ton contexte
     
    LastRow = WsDestination.Range("A" & Rows.Count).End(xlUp).Row
     
    Application.Calculation = xlManual
     
    For Each x In Range("S8", Range("U65000").End(xlUp).Offset(0, -1))
     
     
    'Si valcell = NOK copier les Celulles concernées depuis la feuille (Developpement)  et coller dans la feuille (LUP)
     
     
    If x = "NOK" Then
     
        With WsDepart
        Range("E6:H6").UnMerge
        End With
        With WsDestination
        End With
     
        With WsDepart
        WsDepart.Range("E6").Copy
        WsDestination.Range("B" & LastRow + 1).PasteSpecial xlPasteValues
        End With
     
        WsDepart.Range("C18").Copy
        WsDestination.Range("G" & LastRow + 1).PasteSpecial xlPasteValues
        With WsDepart
        Range("E6:H6").Merge
        End With
     
        WsDepart.Range("AA4").Copy
        WsDestination.Range("C" & LastRow + 1).PasteSpecial xlPasteValues
     
     
        WsDepart.Range("V5").Copy
        WsDestination.Range("D" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("AA1").Copy
        WsDestination.Range("E" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("Y5").Copy
        WsDestination.Range("F" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("F1").Copy
        WsDestination.Range("G" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("Y6").Copy
        WsDestination.Range("H" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("Y5").Copy
        WsDestination.Range("I" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("B8").Copy
        WsDestination.Range("J" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("V8").Copy
        WsDestination.Range("K" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("B8").Copy
        WsDestination.Range("J" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("AF3").Copy
        WsDestination.Range("L" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("AF3").Copy
        WsDestination.Range("M" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("AF3").Copy
        WsDestination.Range("N" & LastRow + 1).PasteSpecial xlPasteValues
     
        WsDepart.Range("AF3").Copy
        WsDestination.Range("O" & LastRow + 1).PasteSpecial xlPasteValues
     
     
        'WsDepart.Range("C15:C22").ClearContents
     
        Set WsDestination = Nothing
        Set WsDepart = Nothing
     
    End If
     
    Application.Calculation = xlAutomatic
    Application.DisplayAlerts = True
     
       'attention a spécifié la variable de la fonction next
    Next x
     
    Application.ScreenUpdating = True
     
    End Sub

  2. #2
    Expert confirmé
    Homme Profil pro
    Responsable des études
    Inscrit en
    Juillet 2014
    Messages
    2 681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aude (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Responsable des études
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2014
    Messages : 2 681
    Par défaut
    Bonjour,

    Merci d'utiliser les balises code (bouton #) pour rendre le code plus lisible.
    Si tu pouvais aussi préciser a quelle ligne tu as l'erreur, tu auras surement plus de réponse.

    je voulais copier (source) et coller (destination) sur une autre feuille du meme fichier ou d'un autre fichier du même dossier, si c’est NOK
    Ca peut se faire sans boucle (donc plus rapidement), je te conseille la lecture de ce tuto: http://philippetulliez.developpez.co...dvancedfilter/

    edit:
    A quoi te servent tout ces with ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    With WsDepart
     Range("E6:H6").UnMerge
     End With
     With WsDestination
     End With
    Ici le With WsDestination se termine juste en dessous donc il ne sert a rien
    Et le With WsDepart n'est pas utilisé puisqu'il n'y a pas de point devant le range à la ligne du dessous.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    With WsDepart
     WsDepart.Range("E6").Copy
     WsDestination.Range("B" & LastRow + 1).PasteSpecial xlPasteValues
     End With
    idem tu met un with que tu n'utilise pas
    soit tu écrit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     WsDepart.Range("E6").Copy
    soit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    With WsDepart
    .Range("E6").Copy

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Juin 2014
    Messages : 16
    Par défaut
    Bonjour,

    Merci pour votre réponse,

    j'ai l'erreur au niveau de cette ligne de code, et quand je vais dans mon fichier excel, il me copie la premiere ligne et puis s'arrete en mettant "erreur d'exécution 91"

    WsDepart.Range("E6").Copy


    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
     Sub MacroCopieCellIfNOk()
     
    Dim x As Variant
     
    Dim LastRow As Long
    Dim WsDepart As Worksheet
    Dim WsDestination As Worksheet
     
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
     
     
    Set WsDestination = SHEETS("Lup")
    Set WsDepart = SHEETS("Developpement")
     
     
    ' Cela suppose que la colonne S soit remplie
    ' avec qqs données sinon à adapter à ton contexte
     
    LastRow = WsDestination.Range("A" & Rows.Count).End(xlUp).Row
     
    Application.Calculation = xlManual
     
    For Each x In Range("S8", Range("U65000").End(xlUp).Offset(0, -1))
     
     
    'Si valcell = NOK copier les Celulles concernées depuis la feuille (Developpement) et coller dans la feuille (LUP)
     
     
    If x = "NOK" Then
     
    With WsDepart
    Range("E6:H6").UnMerge
    End With
    With WsDestination
    End With
     
    With WsDepart
    WsDepart.Range("E6").Copy
    WsDestination.Range("B" & LastRow + 1).PasteSpecial xlPasteValues
    End With
     
    WsDepart.Range("C18").Copy
    WsDestination.Range("G" & LastRow + 1).PasteSpecial xlPasteValues
    With WsDepart
    Range("E6:H6").Merge
    End With
     
    WsDepart.Range("AA4").Copy
    WsDestination.Range("C" & LastRow + 1).PasteSpecial xlPasteValues
     
     
    WsDepart.Range("V5").Copy
    WsDestination.Range("D" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("AA1").Copy
    WsDestination.Range("E" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("Y5").Copy
    WsDestination.Range("F" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("F1").Copy
    WsDestination.Range("G" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("Y6").Copy
    WsDestination.Range("H" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("Y5").Copy
    WsDestination.Range("I" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("B8").Copy
    WsDestination.Range("J" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("V8").Copy
    WsDestination.Range("K" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("B8").Copy
    WsDestination.Range("J" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("AF3").Copy
    WsDestination.Range("L" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("AF3").Copy
    WsDestination.Range("M" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("AF3").Copy
    WsDestination.Range("N" & LastRow + 1).PasteSpecial xlPasteValues
     
    WsDepart.Range("AF3").Copy
    WsDestination.Range("O" & LastRow + 1).PasteSpecial xlPasteValues
     
     
    'WsDepart.Range("C15:C22").ClearContents
     
    Set WsDestination = Nothing
    Set WsDepart = Nothing
     
    End If
     
    Application.Calculation = xlAutomatic
    Application.DisplayAlerts = True
     
    'attention a spécifié la variable de la fonction next
    Next x
     
    Application.ScreenUpdating = True
     
    End Sub

  4. #4
    Expert confirmé
    Homme Profil pro
    Responsable des études
    Inscrit en
    Juillet 2014
    Messages
    2 681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aude (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Responsable des études
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2014
    Messages : 2 681
    Par défaut
    J'ai édité mon message précédent sur l'utilisation des with.

    Je ne comprends pas ce que tu fais avec ta boucle, peut importe la valeur de x c'est toujours les même lignes que tu copies.

  5. #5
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Juin 2014
    Messages : 16
    Par défaut
    Bjr

    je ne veux pas copier la même ligne, je veux copier la ligne correspondant à la cellule où j'ai un Nok, mais pas la ligne quelques cellules à des colonnes spécifiques
    Par exemple si j'ai un Nok, je copie quelques titre en haut de feuille les lignes 1 à 8 et les autres données, sur la meme ligne mais à des colones différentes

    Merci beaucoup

  6. #6
    Expert confirmé
    Homme Profil pro
    Responsable des études
    Inscrit en
    Juillet 2014
    Messages
    2 681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aude (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Responsable des études
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2014
    Messages : 2 681
    Par défaut
    Citation Envoyé par papisco871 Voir le message
    je ne veux pas copier la même ligne, je veux copier la ligne correspondant à la cellule où j'ai un Nok, mais pas la ligne quelques cellules à des colonnes spécifiques
    Par exemple si j'ai un Nok, je copie quelques titre en haut de feuille les lignes 1 à 8 et les autres données, sur la meme ligne mais à des colones différentes
    J'insiste tu devrais vraiment essayer de passer un filtre, cf le lien de mon premier message

  7. #7
    Expert éminent Avatar de Menhir
    Homme Profil pro
    Ingénieur
    Inscrit en
    Juin 2007
    Messages
    16 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 16 037
    Par défaut
    Je pense que tu n'as pas du tout compris le principe des structures With.
    La plupart de celles se trouvant dans ton code sont inutiles et celles qui pourraient être utiles ne sont pas utilisées correctement.
    Lis ça : https://msdn.microsoft.com/fr-fr/VBA...with-statement

Discussions similaires

  1. Réponses: 14
    Dernier message: 23/05/2016, 14h05
  2. erreur d'exécution 91 variable objet ou variable de bloc with non définie
    Par ramo123469 dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 01/04/2016, 14h55
  3. [XL-2013] erreur d'exécution 91 variable objet ou variable de bloc with non définie
    Par tmlpqsdpmdlc dans le forum Macros et VBA Excel
    Réponses: 18
    Dernier message: 08/06/2015, 13h25
  4. Réponses: 6
    Dernier message: 24/02/2015, 09h06
  5. Réponses: 4
    Dernier message: 24/05/2014, 19h24

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