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 :

Problème avec WorksheetFunction.VLookup


Sujet :

Macros et VBA Excel

  1. #1
    Membre averti
    Homme Profil pro
    alternant
    Inscrit en
    Mai 2017
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : alternant
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2017
    Messages : 16
    Par défaut Problème avec WorksheetFunction.VLookup
    Bonjour,

    Débutant en VBA ,j'ai un problème avec la fonction "WorksheetFunction.VLookup" il me sort l'erreur comme quoi il n'arrive pas a lire la fonction...

    Donc en reprenant depuis le début, on m'a donné un fichier qui fonctionne correctement et on me demande de rajouter une colonne et de lui appliquer une rechercheV automatique. La personne qui a créé le fichier l'a fait avec l'enregistreur de macro. J'ai commencé à bidouiller de la ligne 337 à 369 et j'ai aussi adapter le reste en fonction du décalage créé par l'ajout de la colonne.

    Dans un premier temps voici la macroglobal :

    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
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    Sub MacroGlobale()
     
        Sheets("Feuil1").Select
        Selection.AutoFilter
        Sheets("MA43110").Select
        Cells.Select
        Selection.Copy
        Sheets("Feuil1").Select
        ActiveSheet.Paste
        Columns("E:F").Select
        Application.CutCopyMode = False
        Selection.Cut
        Columns("C:C").Select
        Selection.Insert Shift:=xlToRight
        ActiveWindow.ScrollColumn = 2
        ActiveWindow.ScrollColumn = 3
        Columns("T:T").Select
        Selection.Cut
        Columns("I:I").Select
        Selection.Insert Shift:=xlToRight
        Columns("I:U").Select
        Selection.Cut
        Columns("E:E").Select
        Selection.Insert Shift:=xlToRight
        ActiveWindow.ScrollColumn = 4
        ActiveWindow.ScrollColumn = 5
        ActiveWindow.ScrollColumn = 6
        ActiveWindow.ScrollColumn = 8
        ActiveWindow.ScrollColumn = 10
        ActiveWindow.ScrollColumn = 13
        ActiveWindow.ScrollColumn = 16
        ActiveWindow.ScrollColumn = 19
        ActiveWindow.ScrollColumn = 22
        ActiveWindow.ScrollColumn = 24
        ActiveWindow.ScrollColumn = 26
        ActiveWindow.ScrollColumn = 27
        ActiveWindow.ScrollColumn = 28
        ActiveWindow.ScrollColumn = 29
        ActiveWindow.ScrollColumn = 30
        ActiveWindow.ScrollColumn = 31
        ActiveWindow.ScrollColumn = 32
        ActiveWindow.ScrollColumn = 33
        ActiveWindow.ScrollColumn = 34
        ActiveWindow.ScrollColumn = 35
        ActiveWindow.ScrollColumn = 36
        ActiveWindow.ScrollColumn = 37
        ActiveWindow.ScrollColumn = 36
        ActiveWindow.ScrollColumn = 35
        ActiveWindow.ScrollColumn = 34
        ActiveWindow.ScrollColumn = 33
        ActiveWindow.ScrollColumn = 32
        ActiveWindow.ScrollColumn = 31
        Columns("AJ:AJ").Select
        Selection.Cut
        Columns("AM:AM").Select
        Selection.Insert Shift:=xlToRight
        Columns("AL:AN").Select
        Selection.Cut
        Columns("E:E").Select
        Selection.Insert Shift:=xlToRight
        Columns("A:A").ColumnWidth = 13
        Columns("B:B").ColumnWidth = 114
        Columns("C:C").ColumnWidth = 11.43
        Range("F11").Select
        Columns("D:D").ColumnWidth = 19.86
        Columns("E:E").ColumnWidth = 24
        Columns("F:F").ColumnWidth = 40
        Columns("G:G").ColumnWidth = 32.29
        Range("A1:G1").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Interior
            .ColorIndex = 33
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
        End With
        Range("A2:G300").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 1
        End With
        Range("G1").Select
        Range("A1:AN300").Sort Key1:=Range("G2"), Order1:=xlAscending, Header:= _
            xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortTextAsNumbers
        Columns("G:G").Select
        Selection.Insert Shift:=xlToRight
        Range("H1").Select
        Selection.Copy
        Range("G1").Select
        ActiveSheet.Paste
        Range("G2").Select
        Application.CutCopyMode = False
        ActiveCell.FormulaR1C1 = "=RC[1]*1"
        Range("G2").Select
        Selection.NumberFormat = "m/d/yyyy"
        Selection.Copy
        Range("G2:G300").Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        Range("G2:G300").Select
        Selection.Copy
        Range("G2").Select
        ActiveWindow.SmallScroll Down:=-9
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Columns("H:H").Select
        Application.CutCopyMode = False
        Selection.Delete Shift:=xlToLeft
     
    'rajouter la colonne
        Columns(8).Insert
    'Colle le titre de la colonne
        Sheets("Feuil2").Select
         Range("B1").Select
         Selection.Copy
         Sheets("Feuil1").Select
         Range("H1").Select
         ActiveSheet.Paste
    'Permet de centrer le texte
          With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
    'Permet de faire les rechercheV
     
        With Sheets("Feuil1")
        .Range("H2").Value = WorksheetFunction.VLookup(.Range("A2").Value, Sheets("Feuil2").Range("A2:B300"), 2, False)
        End With
        'With Sheets("Feuil1")
        '.Range("H3").Value = WorksheetFunction.VLookup(.Range("A3").Value, Sheets("Feuil2").Range("A2:B300"), 2, False)
        'End With
    'Permet de remettre les bordures aux colonnes
    For Each cellule In Range("H:H")
       If cellule <> "" Then cellule.Borders.Weight = xlThin
    Next
     
        Range("AU1").Select
        ActiveCell.FormulaR1C1 = "=NOW()"
        Range("AV1").Select
        ActiveCell.FormulaR1C1 = "=NOW()+30"
        Range("AV1").Select
        Selection.End(xlToLeft).Select
        Selection.End(xlToLeft).Select
        Selection.End(xlToLeft).Select
        Range("G2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.FormatConditions.Delete
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
            Formula1:="=$AU$1"
        Selection.FormatConditions(1).Font.ColorIndex = 3
        Selection.FormatConditions(1).Interior.ColorIndex = 36
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
            Formula1:="=$AU$1", Formula2:="=$AU$1"
        Selection.FormatConditions(2).Interior.ColorIndex = 40
        ActiveWindow.LargeScroll ToRight:=-1
           Range("G1").Select
        Range("A1:AN300").Sort Key1:=Range("G2"), Order1:=xlAscending, Header:= _
            xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
        ActiveWindow.SmallScroll Down:=-21
     
         Range("C2").Select
        Selection.FormatConditions.Delete
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
            Formula1:="=""En Retard"""
        With Selection.FormatConditions(1).Font
            .Bold = True
            .Italic = False
            .ColorIndex = 3
        End With
        Selection.FormatConditions(1).Interior.ColorIndex = 36
        Selection.Copy
        Range("C3:C300").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
        Range("A1").Select
    Ensuite voici dans cette macro l'endroit que j'ai ajouté et qui ne fonctionne pas :

    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
    'rajouter la colonne
        Columns(8).Insert
    'Colle le titre de la colonne
        Sheets("Feuil2").Select
         Range("B1").Select
         Selection.Copy
         Sheets("Feuil1").Select
         Range("H1").Select
         ActiveSheet.Paste
    'Permet de centrer le texte
          With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
    'Permet de faire les rechercheV
     
        With Sheets("Feuil1")
        .Range("H2").Value = WorksheetFunction.VLookup(.Range("A2").Value, Sheets("Feuil2").Range("A2:B300"), 2, False)
        End With
        'With Sheets("Feuil1")
        '.Range("H3").Value = WorksheetFunction.VLookup(.Range("A3").Value, Sheets("Feuil2").Range("A2:B300"), 2, False)
        'End With
    'Permet de remettre les bordures aux colonnes
    For Each cellule In Range("H:H")
       If cellule <> "" Then cellule.Borders.Weight = xlThin
    Next
    l'erreur qui m'es indiqué est : erreur d'éxécution '1004' : Impossible de lire la propriété VLookup de la classe WorksheetFunction

    Sur cette ligne-ci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     .Range("H2").Value = WorksheetFunction.VLookup(.Range("A2").Value, Sheets("Feuil2").Range("A2:B300"), 2, False)
        End With



    En attente de vos réponse,

  2. #2
    Expert éminent
    Avatar de Marc-L
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2013
    Messages
    9 468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2013
    Messages : 9 468
    Par défaut

    Bonjour,

    conformément aux règles de ce forum, merci de présenter exactement le numéro et le message d'erreur
    accompagné du code - balisé via l'icône # - relatif à cette erreur et en indiquant la ligne la déclenchant !

    ___________________________________________________________________________________________________________
    Je suis Paris, Egypte, Stockholm, London, Istanbul, Berlin, Nice, Bruxelles, Charlie, …

  3. #3
    Membre Expert
    Femme Profil pro
    Ingénieur
    Inscrit en
    Octobre 2016
    Messages
    1 703
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 30
    Localisation : France, Indre et Loire (Centre)

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

    Informations forums :
    Inscription : Octobre 2016
    Messages : 1 703
    Par défaut
    Bonjour et bienvenue au forum
    Conformément aux règles du forum, ne joints pas de fichier, mais :
    • Ecris le code qui fait défaut entre balises (bouton #)
    • Décris-nous ton problème et le contexte.
    • Donne-nous l'éventuel message d'erreur et sa localisation dans le code.
    • S'il n'y a pas d'erreur explique nous ce qui ne va pas dans ton code.

    N'hésite pas à faire un tour sur d'autres discussions du forum pour voir comment présenter ton problème.
    Explications sur VLookUp : https://msdn.microsoft.com/en-us/lib.../ff194701.aspx
    A bientôt avec plus de précisions

  4. #4
    Membre averti
    Homme Profil pro
    alternant
    Inscrit en
    Mai 2017
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : alternant
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2017
    Messages : 16
    Par défaut
    finalement c'est bon l'erreur c'était qu'il fallait convertir les nombres dans les colonnes de la feuille 1 et 2 pour qu'ils soient reconnues et utilisable. =)

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

Discussions similaires

  1. [XL-2013] Problème avec fonction vlookup
    Par iseulysse dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 15/01/2015, 10h45
  2. [XL-2003] VBA - Problème avec WorksheetFunction.Match
    Par oracle7556 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 08/07/2010, 16h02
  3. Problème avec : worksheetfunction.vlookup
    Par kanabeachpro dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 23/11/2008, 23h41
  4. quel code écrire en cas d'erreur avec "worksheetfunction.vlookup"
    Par lerouxjm dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 19/12/2007, 17h38
  5. [VBA][EXCEL]PB avec la commande WorksheetFunction.VLookup
    Par Ania dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 02/11/2005, 16h41

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