Private Sub Worksheet_Change(ByVal Target As Range) '如果填写,则改变颜色。
Dim sh As Range, d As Range
With Target
If .Cells.Count = 1 And .Column = 2 And Len(.Text) > 0 Then
Set sh = Sheets("产品库").Range("B:B")
Set d = sh.Find(.Value, LookIn:=xlValues, Lookat:=xlWhole)
If Not d Is Nothing Then
.Offset(0, 1).Value = d.Offset(0, 1).Value
.Offset(0, -1).Value = d.Offset(0, -1).Value
Else
.Offset(0, 1).Value = "找不到该产品编码"
.Offset(0, -1).Value = "找不到该产品编码"
End If
End If
End With
End Sub