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
|
Dim res As Variant
Dim mavaleur As Variant
Dim maPlage As Range
Dim macolonne As Single
Dim valeurproche As Boolean
' Fonction RechercheV
Function RECHERCHEV(Valeur_Cherchee As Variant, Table_matrice As Range, No_index_col As Single, Optional Valeur_proche As Boolean)
If Valeur_Cherchee = "" Then
MsgBox "La valeur recherchée est vide", _
vbInformation, "Hey"
Else
RECHERCHEV = Application.WorksheetFunction.VLookup(Valeur_Cherchee, Table_matrice, No_index_col, Valeur_proche)
End If
End Function
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Cells.CountLarge > 1 Then
Else
ligne = ActiveCell.Row
' Validation de données
With Range("B" & ligne).Validation
.Delete
End With
' Gestion de validation des données Case à cocher de Statut nouveauté web
If Not Intersect(Target, Range("B1:B20")) Is Nothing Then
liste = "=Feuil2!$A$2:$A$7"
With Range("B" & ligne).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=liste
End With
End If
' RechercheV pour la colonne ID
If Not Intersect(Target, Range("A1:A20")) Is Nothing Then
If Not Target.Address = "$A$1" Then
Set maPlage = Sheets("Feuil2").Range("A1:B7")
macolonne = 2
valeurproche = False
mavaleur = Cells(ligne, 2).Value
res = RECHERCHEV(mavaleur, maPlage, macolonne, valeurproche)
Cells(ligne, 1).Value = res
End If
End If
End If
End Sub |
Partager