|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ar, br, i&, j&, r&, dic As Object, strFind$
If Target.Address <> "$B$2" Then Exit Sub
If Target.Value = "" Then Exit Sub Else strFind = Target.Value
Set dic = CreateObject("Scripting.Dictionary")
ar = Sheets(1).[A1].CurrentRegion.Value
For j = 1 To UBound(ar, 2)
dic(ar(1, j)) = j
Next j
Application.EnableEvents = False
With [D1].CurrentRegion
.Offset(1).Clear
br = .Resize(UBound(ar))
r = 1
End With
For i = 1 To UBound(ar)
If ar(i, 2) = strFind Then
r = r + 1
br(r, 1) = i
For j = 2 To UBound(br, 2)
If dic.exists(br(1, j)) Then
br(r, j) = ar(i, dic(br(1, j)))
End If
Next j
End If
Next i
[D1].Resize(r, UBound(br, 2)) = br
Application.EnableEvents = True
Set dic = Nothing
Beep
End Sub
|
|