帮你简单的实现了一下,自己完善一下 Private Sub Worksheet_Change(ByVal Target As Range)
Dim iKey, rng As Range, iR As Integer
Application.EnableEvents = False
With Target
If .Count = 1 Then
If .Address = "$K$2" And .Value <> "" Then
iKey = .Value
Set rng = Sheet1.Columns("I")
If Application.WorksheetFunction.CountIf(Sheet1.Columns(9), iKey) = 0 Then
MsgBox "Can't find " & .Value
.Value = ""
Exit Sub
Else
Range("A5:L31").ClearContents
iR = 5
Set c = rng.Find(iKey, , xlValues, xlWhole)
If Not c Is Nothing Then
stAdd = c.Address
Do
Cells(iR, 1) = c.Offset(0, -6)
Cells(iR, 3) = c.Offset(0, -4)
Cells(iR, 4) = c.Offset(0, -3)
Cells(iR, 5) = c.Offset(0, -2)
iR = iR + 1
Set c = rng.FindNext(c)
Loop While Not c Is Nothing And c.Address <> stAdd
End If
End If
End If
End If
End With
Application.EnableEvents = True
End Sub |