Board logo

標題: [發問] 請教有關Dictionary用法 [打印本頁]

作者: Lin-excel    時間: 2019-4-12 20:10     標題: 請教有關Dictionary用法

請教諸位先輩高手,煩請指出錯在哪裡?[attach]30373[/attach]不知哪出錯?沒有辦法執行!

Dim Km As Object, Arr()
Private Sub Worksheet_Activate()
    Dim i%
    Set Km = CreateObject("Scripting.Dictionary")
    Arr = Range("j3:m" & Range("j" & Rows.Count).End(3).Row).Value
    For i = 1 To UBound(Arr)
        Km(Arr(i, 1)) = i   '把代碼和對應的序號裝入字典
    Next
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("B3:B126")) Is Nothing Then Exit Sub

    Application.EnableEvents = False
'        Target.Value = Cells(Rows.Count, "B").End(xlUp).Offset(1, 1)
        Target.Offset(0, -1).Value = Date
        For i = 1 To 3
            Target.Offset(0, i).Value = Arr(Km(Target.Value), i + 1)
        Next
'        Target.Resize(1, 3).Value = Arr(Km(Target.Value).Items)
    Application.EnableEvents = True

End Sub
[attach]30373




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)