Bonjour,
La macro suivante a été rédigée avec l'aide du forum (je remercie job75) :
Je souhaiterais pouvoir y introduire une gestion des erreurs du même accabit que la macro écrite par Lii :
Merci pour votre aide
La macro suivante a été rédigée avec l'aide du forum (je remercie job75) :
Private Sub Worksheet_Change(ByVal Target As Range)
Dim col1 As Range, col2 As Range, ref As Range, txt$
On Error Resume Next
Set col1 = Rows(1).Find("CODE POSTAL", LookIn:=xlFormulas, LookAt:=xlPart).Offset(1).Resize(Rows.Count - 1)
Set col2 = Rows(1).Find("BUREAU DISTRIBUTEUR").Offset(1).Resize(Rows.Count - 1)
If Intersect(Target, Union(col1, col2)) Is Nothing Then Exit Sub
With Sheets("CODESPOSTAUX")
Set ref = .Range("A:B").Find(Target, LookAt:=xlWhole)
If IsNumeric(Target) And Not Intersect(Target, col1) Is Nothing Then
txt = .Cells(ref.Row, 2)
ElseIf Not IsNumeric(Target) And Not Intersect(Target, col2) Is Nothing Then
txt = .Cells(ref.Row, 1)
End If
End With
Application.EnableEvents = False
Cells(Target.Row, IIf(Intersect(Target, col1) Is Nothing, col1.Column, col2.Column)) = txt
Application.EnableEvents = True
End Sub
Je souhaiterais pouvoir y introduire une gestion des erreurs du même accabit que la macro écrite par Lii :
On Error GoTo fin 'si le code n'existe pas ou une erreur de saisie (lettres)
Target.Offset(0, -1).Value = Sheets("CODEPOSTAUX").Columns(2).Find(Target.Value, , xlValues, xlWhole).Offset(0, -1)
End
fin:
MsgBox "Le bureau n'existe pas !", , "Attention"
Application.EnableEvents = False
Target = ""
Target.Offset(0, 0).Select
Application.EnableEvents = True
Merci pour votre aide