|
Private Sub Worksheet_Change(ByVal Target As Range)
'检查更改是否发生在C8以下的C列单元格
If Not Intersect(Target, Me.Range("C8:C" & Me.Rows.Count)) Is Nothing Then
'在产品信息工作表中查找匹配的值
Dim ProductSheet As Worksheet
Set ProductSheet = ThisWorkbook.Sheets("产品信息")
Dim SearchRange As Range
Set SearchRange = ProductSheet.Range("C6:C100")
Dim FoundCell As Range
Set FoundCell = SearchRange.Find(Target.Value)
'如果找到匹配的值,显示对应D列的结果在当前E列
If Not FoundCell Is Nothing Then
Me.Cells(Target.Row, "E").Value = ProductSheet.Cells(FoundCell.Row, "D").Value
Me.Cells(Target.Row, "f").Value = ProductSheet.Cells(FoundCell.Row, "e").Value
Else
'如果没有找到,显示空字符串
Me.Cells(Target.Row, "E").Value = ""
Me.Cells(Target.Row, "f").Value = ""
End If
End If
End Sub |
|