|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Private Sub Worksheet_Change(ByVal Target As Range)
Set Rng = Application.Intersect(Columns(2), Target)
If Rng Is Nothing Then Exit Sub '取交集,发生变化的单元格与第2列的有交集,如果没有就退出过程
Set d = CreateObject("scripting.dictionary") '字典对象后期绑定
Application.ScreenUpdating = False '表格刷新
Application.EnableEvents = False '触发事件
arr = Sheets("物料基础数据").UsedRange ' 将引用表格数据放入数组
For i = 1 To UBound(arr)
s = arr(i, 1)
d(s) = Array(arr(i, 1), arr(i, 2), arr(i, 3), arr(i, 4), arr(i, 5), arr(i, 6), arr(i, 7)) '将引用表附值给字典
Next
For Each rn In Rng
r = rn.Row
If r > 1 Then
If Len(rn) = 0 Then '如果单元格值为0
Cells(r, 1).Resize(1, 1).Value = ""
Cells(r, 2).Resize(1, 2).Value = ""
Cells(r, 5).Resize(1, 1).Value = ""
Cells(r, 7).Resize(1, 2).Value = ""
Else
If Not d.exists(rn.Value) Then '如果字典中没有
Cells(r, 1).Resize(1, 1).Value = ""
Cells(r, 2).Resize(1, 2).Value = ""
Cells(r, 5).Resize(1, 1).Value = ""
Cells(r, 7).Resize(1, 2).Value = ""
Else
s = rn.Value
Cells(r, 1).Value = Date '日期
Cells(r, 3).Value = d(s)(1)
Cells(r, 5).Value = d(s)(4)
Cells(r, 7).Value = d(s)(5)
Cells(r, 8).Value = d(s)(3)
End If
End If
End If
Next
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
|
评分
-
1
查看全部评分
-
|