尝试在您的 Sheet1 代码中使用此代码...如果有不清楚的地方,请随时询问。
编辑:稍微改变了清理程序。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oCell As Excel.Range
Dim oCellResult As Excel.Range
Dim oCellClean As Excel.Range
Dim oRangeID As Excel.Range
Dim iCellCount As Integer
If Target.Address = "$C$4" Then
'Set source data
Set oRangeID = Sheets(2).Range("A:A")
'Define initial target for the results obtained
Set oCellResult = Sheets(1).Range("F12")
'Clear up any previous data
'Set oCellClean = oCellResult
'While Len(oCellClean.Value) > 0
'
' oCellClean.Clear
' Set oCellClean = oCellClean.Offset(1, 0)
'
'Wend
Set oCellClean = Range(oCellResult, oCellResult.End(xlDown))
oCellClean.ClearContents
'Scans source range for match data
For Each oCell In oRangeID
If oCell.Value = "" Then Exit For
If oCell.Value = Target.Value Then
oCellResult.Offset(iCellCount, 0).Value = oCell.Offset(0, 2).Value
iCellCount = iCellCount + 1
End If
Next oCell
End If
结束子
编辑:
更新了清理代码。检查它是否符合您的期望。