XL 2016 VBA – Rechercher valeurs dans un tableau et les transférer dans un autre tableau

rounil09

XLDnaute Occasionnel
Malgré mes essais à partir de code récupéré, je n’arrive pas à construire une macro qui fonctionne.

Quelqu’un peut-il me venir en aide ? Explications détaillées dans fichier joint
 

Pièces jointes

  • GB-BDMAJ.xlsx
    14.9 KB · Affichages: 9

laurent3372

XLDnaute Impliqué
Supporter XLD
Bonjour,

Voici une solution:
VB:
Option Explicit

Sub MiseAJour()
    Dim wsPortF As Worksheet, wsMaj As Worksheet
    Dim rLabelPortF As Range, rLabelMaj As Range
    Dim rng As Range
    Dim iMatch As Variant
    
    Set wsPortF = Worksheets("PORTF")
    Set wsMaj = Worksheets("MAJ")
    
    With wsPortF: Set rLabelPortF = .Range(.[B2], .Cells(Rows.Count, "B").End(xlUp)): End With
    With wsMaj: Set rLabelMaj = .Range(.[B2], .Cells(Rows.Count, "B").End(xlUp)): End With
    
    For Each rng In rLabelPortF
        iMatch = Application.Match(rng, rLabelMaj, 0)
        If IsError(iMatch) Then
            MsgBox "La valeur " & rng & " ne se trouve pas dans la liste de mise à jour", vbInformation + vbOKOnly, "Mie à Jour"
        Else
            rng.EntireRow.Resize(, 8).Value = wsMaj.[A1:H1].Offset(iMatch).Value
        End If
    Next rng
 End Sub

Bonne chance,
--
LR
 

Pièces jointes

  • GB-BDMAJ V1.0.xlsm
    28.8 KB · Affichages: 14

Discussions similaires

Statistiques des forums

Discussions
311 733
Messages
2 082 019
Membres
101 872
dernier inscrit
Colin T