Tableau de correspondance

99test-corespond.xlsx (11.03 Ko)
99test-corespond.xlsx (11.03 Ko)

Bonjour à tous,

Soit le tableau ci-dessous

COL A Tableau correspondance1 Tableau correspondance2

CM 0123 CM 01 CAMEROUN FRANCOPHONE

CM 5458 CM 54 CAMEROUN ANGLOPHONE

CM 985T CM 30 CAMEROUN ARABE

CM CAMEROUN

J’aimerai un code qui permettrai remplacer les valeurs de la colonne A par celle de la colonne C (Tableau correspondance2) en se basant uniquement

Les 05 premiers caractère le colonne A ; s’il n’a pas de correspondance, ce baser sur les 02 premiers caractère de la colonne A.

Merci.

COL ACOL CORESP BCOL CORES C

CM 0123CM 01CAMEROUN FRANCOPHONE

CM 5458CM 54CAMEROUN ANGLOPHONE

CM 985TCM 30CAMEROUN ARABE

CMCAMEROUN

Bonjour,

Un essai

Bonjour DJIDJI 59430,

ta formule marche, c'est ok.

mais ce j'aimerai, c'est avoir un bouton '' conversion" par qui remplacera directement les valeurs de la feuille données par celle des correspondance.

d'ou un code en VBA.

merci.

Re

Je suis nul en VBA.

Repose ta question genre " Macro pour remplacement contenu de cellule", ou tu expliques que , une fois validée une cellule, tu voudrais que le contenu de celle-ci soit remplacé par un autre issu d'un tableau.

Désolé

Private Sub CommandButton2_Click()

Dim ws, ws2 As Worksheet

Dim objList As ListObject, objList2 As ListObject, objList3 As ListObject, objList23 As ListObject

Dim Cell As Range

Dim Result As Variant

Application.ScreenUpdating = False

Set ws = Worksheets("Données"): Set ws2 = Worksheets("Feuil3")

Set objList = ws.ListObjects(1): Set objList2 = ws2.ListObjects(1)

With ws

For Each Cell In objList.ListColumns(14).DataBodyRange

Result = Application.VLookup(Cell.Value, objList2.DataBodyRange, 2, False)

If IsError(Result) Then

Cell.Value = "Non Defini"

Else

Cell.Value = Result

End If

Next Cell

End With

With ws

For Each Cell In objList.ListColumns(15).DataBodyRange

Result = Application.VLookup(Cell.Value, objList2.DataBodyRange, 2, False)

If IsError(Result) Then

Cell.Value = "Non Defini"

Else

Cell.Value = Result

End If

Next Cell

End With

With ws

For Each Cell In objList.ListColumns(23).DataBodyRange

Result = Application.VLookup(Cell.Value, objList2.DataBodyRange, 2, False)

If IsError(Result) Then

Cell.Value = "Non Defini"

Else

Cell.Value = Result

End If

Next Cell

End With

Set objList = Nothing: Set objList2 = Nothing

Set ws2 = Nothing: Set ws = Nothing

End Sub

ci dessous un essaie

Bonjour à tous,

J’aimerai un code qui permettrai remplacer les valeurs de la colonne A par celle de la colonne C (Tableau correspondance2) en se basant uniquement sur Les 05 premiers caractères le colonne A ; s’il n’a pas de correspondance, se baser sur les 02 premiers caractères de la colonne A.

BREF

j'aimerai, avoir un bouton '' conversion" par exemple qui remplacera directement les valeurs de la feuille données par celle des correspondances,d’où un code en VBA.

Private Sub CommandButton2_Click()

Dim ws, ws2 As Worksheet

Dim objList As ListObject, objList2 As ListObject, objList3 As ListObject, objList4 As ListObject

Dim Cell As Range

Dim Result As Variant

Application.ScreenUpdating = False

Set ws = Worksheets("Données"): Set ws2 = Worksheets("Feuil3")

Set objList = ws.ListObjects(1): Set objList2 = ws2.ListObjects(1)

With ws

For Each Cell In objList.ListColumns(08).DataBodyRange

Result = Application.VLookup(Cell.Value, objList2.DataBodyRange, 2, False)

If IsError(Result) Then

Cell.Value = "Non Defini"

Else

Cell.Value = Result

End If

Next Cell

End With

Set objList = Nothing: Set objList2 = Nothing

Set ws2 = Nothing: Set ws = Nothing

End Sub


ci dessous un essaie

Bonjour à tous,

J’aimerai un code qui permettrai remplacer les valeurs de la colonne A par celle de la colonne C (Tableau correspondance2) en se basant uniquement sur Les 05 premiers caractères le colonne A ; s’il n’a pas de correspondance, se baser sur les 02 premiers caractères de la colonne A.

BREF

j'aimerai, avoir un bouton '' conversion" par exemple qui remplacera directement les valeurs de la feuille données par celle des correspondances,d’où un code en VBA.

Private Sub CommandButton2_Click()

Dim ws, ws2 As Worksheet

Dim objList As ListObject, objList2 As ListObject, objList3 As ListObject, objList4 As ListObject

Dim Cell As Range

Dim Result As Variant

Application.ScreenUpdating = False

Set ws = Worksheets("Données"): Set ws2 = Worksheets("Feuil3")

Set objList = ws.ListObjects(1): Set objList2 = ws2.ListObjects(1)

With ws

For Each Cell In objList.ListColumns(08).DataBodyRange

Result = Application.VLookup(Cell.Value, objList2.DataBodyRange, 2, False)

If IsError(Result) Then

Cell.Value = "Non Defini"

Else

Cell.Value = Result

End If

Next Cell

End With

Set objList = Nothing: Set objList2 = Nothing

Set ws2 = Nothing: Set ws = Nothing

End Sub

bonjour,

ci dessous un code qui fonctionne.

Private Sub CommandButton4_Click()

Dim C As Range, Plage As Range, Corresp As Range, X As Range

With Sheets("Feuil3")

Set Corresp = .Range("A2", .Cells(.Rows.Count, 2).End(xlUp))

End With

With Sheets("Données")

Set Plage = .Range("A2", .Cells(.Rows.Count, 1).End(xlUp))

For Each C In Plage

If IsNumeric(Application.Match(Left(C.Value, 5), Corresp.Resize(, 1), 0)) Then

C.Value = Application.VLookup(Left(C.Value, 5), Corresp, 2, 0)

Else

C.Value = Application.VLookup(Left(C.Value, 2), Corresp, 2, 0)

End If

Next C

End With

CreateObject("Wscript.shell").Popup "Lieu de Delivrance CNI codifié ", 3, "Codification Lieu Délivrance CNI"

End Sub

Rechercher des sujets similaires à "tableau correspondance"