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
| Option Explicit
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Catch
Application.EnableEvents = False
' // Si vide, ou plusieurs cellules on quitte
If Target.Count > 1 Or Target.Value = vbNullString Then GoTo Catch
' // Si la frappe est dans la colonne B alors on teste
If Not Intersect(Range("B:B"), Target) Is Nothing Then
Dim SearchedRange As Excel.Range
Set SearchedRange = sys_Settings.Range("vt_Pays[Index]").Find(Val(Target.Value), , xlValues, xlWhole)
If Not SearchedRange Is Nothing Then Target.Offset(0, 1).Value = SearchedRange.Offset(0, 1).Value
'Todo "Annuler l'entrée?"
' // Si la frappe est dans la colonne C alors on teste
ElseIf Not Intersect(Range("C:C"), Target) Is Nothing Then
Set SearchedRange = sys_Settings.Range("vt_Pays[Pays]").Find(Target.Value, , xlValues, xlPart)
If Not SearchedRange Is Nothing Then Target.Offset(0, -1).Value = SearchedRange.Offset(0, -1).Value
'Todo "Annuler l'entrée?"
End If
Catch:
If Err.Number > 0 Then
MsgBox "Oups... Nous avons rencontré une erreur : " & Err.Description
Err.Clear
End If
Application.EnableEvents = True
End Sub |
Partager