excel vba 在B列中单元格中输入代码,在相应的A列和C列中输入产品名和单位。

2020-10-28 教育 140阅读
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
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com