



'当前表一工作表change事件
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Rows.Count + Target.Columns.Count > 2 Then Exit Sub
If Target.Row < 3 Then Exit Sub
Dim d, t
Call setdic(d)
t = Cells(2, Target.Column).Value
If Not d(0).exists(t) Then Exit Sub
If d(d(0)(t)).exists(Target.Value) Then
Application.EnableEvents = False
Target.Value = d(d(0)(t))(Target.Value)
Application.EnableEvents = True
End If
End Sub
Function setdic(d)
Dim a, i, j
a = Sheets("表二(代码库)").[a1].CurrentRegion.Value ' 全角括号
If UBound(a, 2) Mod 2 Then MsgBox "偶数行!": End
ReDim d(UBound(a, 2) / 2)
Set d(0) = CreateObject("scripting.dictionary")
For j = 1 To UBound(a, 2) Step 2
If Len(a(1, j + 1)) Then
d(0)(a(1, j + 1)) = (j + 1) / 2
Set d((j + 1) / 2) = CreateObject("scripting.dictionary")
For i = 2 To UBound(a)
If Len(a(i, j)) Then d((j + 1) / 2)(a(i, j)) = a(i, j + 1)
Next
End If
Next
End Function