1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Option Explicit
Private Sub Worksheet_Change(ByVal target As Range)
Dim xlwbs As Worksheet, xlwbs1 As Worksheet
Dim rng As Range, cell As Range
Dim intersection As Range
Dim Lmax As Integer, Lmax1 As Integer
Set xlwbs = ThisWorkbook.Worksheets("NINF")
Set xlwbs1 = ThisWorkbook.Worksheets("UF")
Lmax = xlwbs.Cells(Rows.Count, 1).End(xlUp).Row
Lmax1 = xlwbs1.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = xlwbs.Range(Cells(4, 2), Cells(Lmax, 2))
Set intersection = Intersect(target, rng)
Application.EnableEvents = False
If Not intersection Is Nothing Then
rng.Offset(, 1) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(rng, xlwbs1.Range("A2:B" & Lmax1), 2, False), "")
End If
Application.EnableEvents = True
End Sub |
Partager