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 :

variable objet ou variable bloc with non définie 91


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 6
    Par défaut variable objet ou variable bloc with non définie 91
    Bonjour,

    je souhaite extraire les dernières lignes de commentaire de cellule si la cellule comporte un commentaires, je boucle trois fois
    lors du premier passage cela se passe bien par contre au deuxième j'ai une erreur : celle notée dans l'intitulé.

    je vous joins copie d’écran du code

    voila partir de 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
    Periode = Cells(LigneFeuille, CompteurCol - 1).Value
    MsgBox Periode
    Engin = Cells(LigneFeuille, CompteurCol - 3).Value
     
    For N = 1 To 3
    LigneFeuille = LigneFeuille + 2
    Fonction = Cells(LigneFeuille - 2, CompteurCol - 2).Value
        '*** extraction commentaire ***
    If Cells(LigneFeuille - 2, CompteurCol).Comment.Text <> "" Then
    x = Len(Cells(LigneFeuille - 2, CompteurCol).Comment.Text)
    For i = x To 1 Step -1
    If Mid(Cells(LigneFeuille - 2, CompteurCol).Comment.Text, i, 1) = ":" Then
    Exit For
    End If
    Next i
     
       Commentaires = Right(Cells(LigneFeuille - 2, CompteurCol).Comment.Text, x - i - 1)
     
        Workbooks("test_saisie.xlsm").Activate
        Sheets("test").Select
        Cells(Lg, 1).Activate
        ActiveCell.Offset(0, 4) = Commentaires
        ActiveCell.Offset(0, 1) = Periode
        ActiveCell.Offset(0, 3) = Fonction
        ActiveCell.Offset(0, 2) = Engin
    Else
        Workbooks("stat.xlsx").Activate
        Sheets("test").Select
    End If
     
    Next N
     
    '*** fermeture fichier stats ***
    Workbooks("stat.xlsx").Close SaveChanges:=False
    Fin:
    la ligne 9 marque l erreur

    merci d'avance

    slts

  2. #2
    barpasc
    Invité(e)
    Par défaut
    Bonjour,

    On ne voit pas le début de votre code. mais essayer de déclarer LigneFeuille et CompteurCol avec

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    dim LigneFeuille as long
    dim CompteurCol as long
    au début de votre code ou avant l'instruction if

    Pascal

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 6
    Par défaut
    désolé je n'avais pas tout mis effectivement voila le code complet cela fonctionnait jusqu'à ce que j'ajoute la boucle N

    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
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    Dim nom As String
    Dim NomfichierOuvert As String
    Dim Moiscourant As String
    Dim Moi As Integer
    Dim NomFeuille As String
    Dim LigneFeuille As Long
     
     
     
    Moi = Application.InputBox("Mois de saisie en chiffre ?")
     
    'Moi = Month(Range("H5").Value)
    MsgBox Moi
     
    If Moi = 1 Then
    Moiscourant = "janvier"
       ElseIf M = 2 Then
        Moiscourant = "février"
            ElseIf Moi = 3 Then
            Moiscourant = "mars"
               ElseIf Moi = 4 Then
               Moiscourant = "avril"
                    ElseIf Moi = 5 Then
                    Moiscourant = "mai"
                        ElseIf Moi = 6 Then
                        Moiscourant = "juin"
                            ElseIf Moi = 7 Then
                            Moiscourant = "juillet"
                                ElseIf Moi = 8 Then
                                Moiscourant = "août"
                                    ElseIf Moi = 9 Then
                                    Moiscourant = "septembre"
                                        ElseIf Moi = 10 Then
                                        Moiscourant = "octobre"
                                            ElseIf Moi = 11 Then
                                            Moiscourant = "novembre"
                                                Else
                                                Moiscourant = "décembre"
    End If
     
    NomFeuille = Moiscourant & " " & Year(Date)
    MsgBox NomFeuille
     
    NomfichierOuvert = ThisWorkbook.Name
    MsgBox NomfichierOuvert
     
     
        ' ******* tri sur le nom SP *******
            ' *** SLA ***
    Dim Lg As Integer
    Lg = 1
     
    statSP:
    Lg = Lg + 1
    Cells(Lg, 1).Activate
    nom = ActiveCell.Value 'Range("A1").Value
    nom = UCase(nom)
    MsgBox nom
    correction:
     
        ' *** recherche personnel pour stat sur vehicule ***
     
    Dim Nomfichier As String, chemin As String
    Dim wbExcel As Workbook
        Nomfichier = "Stat.xlsx" 'fichier a ouvrir pour incrémenter
        chemin = "C:\Users\pc_warriors\Documents\MTY_RH\test\"
            Set wbExcel = Workbooks.Open(chemin & Nomfichier)
    Dim CompteurCol As Long
    'Dim AjoutCol As Integer
    'Dim Valeur As Integer
    Dim Periode As String
    Dim ColFct As Integer
    'Dim Vehicule As Integer
    Dim Fonction As String
    Dim Engin As String
    Dim Commentaires As String
    Dim N As Integer
     
     
     
     
     
        Workbooks("stat.xlsx").Activate
        Sheets("test").Select
     
        Range("C1").Select
     
    CompteurCol = 2  ' Changer la valeur pour chaque macro
    LigneFeuille = 2
     
     
    Do
    CompteurCol = CompteurCol + 1
       If Cells(1, CompteurCol).Formula = "F" Then
        MsgBox ("Le SP : " & nom & " n'existe pas")
        Exit Do
        End If
            Loop While Cells(1, CompteurCol).Formula <> nom
            MsgBox CompteurCol
     
     
     
     
    Periode = Cells(LigneFeuille, CompteurCol - 1).Value
    MsgBox Periode
    Engin = Cells(LigneFeuille, CompteurCol - 3).Value
     
    For N = 1 To 3
     
    LigneFeuille = LigneFeuille + 2
    Fonction = Cells(LigneFeuille - 2, CompteurCol - 2).Value
        '*** extraction commentaire ***
    If Cells(LigneFeuille - 2, CompteurCol).Comment.Text <> "" Then
    x = Len(Cells(LigneFeuille - 2, CompteurCol).Comment.Text)
    For i = x To 1 Step -1
    If Mid(Cells(LigneFeuille - 2, CompteurCol).Comment.Text, i, 1) = ":" Then
    Exit For
    End If
    Next i
     
       Commentaires = Right(Cells(LigneFeuille - 2, CompteurCol).Comment.Text, x - i - 1)
     
        Workbooks("test_saisie.xlsm").Activate
        Sheets("test").Select
        Cells(Lg, 1).Activate
        ActiveCell.Offset(0, 4) = Commentaires
        ActiveCell.Offset(0, 1) = Periode
        ActiveCell.Offset(0, 3) = Fonction
        ActiveCell.Offset(0, 2) = Engin
    Else
        Workbooks("stat.xlsx").Activate
        Sheets("test").Select
    End If
     
    Next N
     
    '*** fermeture fichier stats ***
    Workbooks("stat.xlsx").Close SaveChanges:=False
    Fin:
     
     
    End Sub

  4. #4
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par yanchs Voir le message
    Bonjour,

    Les commentaires font parties de la collection Comments, il faut donc les tester de cette manière :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    If Not Cells(LigneFeuille - 2, CompteurCol).Comment Is Nothing Then
    '....
    End If
    La même chose serait à faire si vous aviez les nouveaux commentaires de type CommentThreaded de la collection CommentsThreaded.

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 6
    Par défaut super
    merci beaucoup Eric

    cela fonctionne

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Variable objet ou variable bloc With non définie
    Par Andriantsilaizina dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 18/01/2017, 14h51
  2. Variable objet ou variable bloc With non définie !
    Par messahel dans le forum Windows
    Réponses: 0
    Dernier message: 17/02/2014, 15h16
  3. [XL-2003] Variable objet ou variable bloc With non définie
    Par PrincessGirl dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 21/05/2012, 16h04
  4. Variable objet ou variable bloc with non définie
    Par tarbala dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 06/05/2008, 12h19
  5. Réponses: 13
    Dernier message: 01/06/2006, 17h20

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