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
|
Dim liste As String
' RechercheV
Dim res As Variant
Dim mavaleur As Variant
Dim maPlage As Range
Dim macolonne As Single
Dim valeurproche As Boolean
Dim ligne As Integer
' 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_Change(ByVal Target As Range)
If Selection.Cells.CountLarge > 1 Then
Else
ligne = ActiveCell.Row
If Not Intersect([B1:B20], Target) Is Nothing And Target.Count = 1 Then
' RechercheV pour la colonne ID
If Not Target.Address = "$A$1" Then
Set maPlage = Sheets("Feuil2").Range("A1:B7")
macolonne = 2
valeurproche = False
mavaleur = Cells(ligne, 2).Value
' Appel de la fonction RechercheV
res = RECHERCHEV(mavaleur, maPlage, macolonne, valeurproche)
' Pour l'affichage : passe le resulatat à la cellule
Cells(ligne, 1).Value = res
End If
End If
End If
End Sub
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
' La feuille de la liste dépendante
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
End If
End Sub |
Partager