VBA 下拉列表 onchange

VBA drop downlist onchange

嘿,我想知道它是否可行:目前我在 sheet1 上有一个下拉列表,其中包含从 sheet2[ 中提取的名称列表=22=] 使用数据验证。 该下拉列表旁边的单元格使用来自 sheet2.
的 VLOOKUP 填充了 phone 数字 我的问题:我可以使用 VBA 以便每次下拉列表发生变化时,它旁边的单元格都会由 SHEET2 中的数据填充?请记住,需要选择的值才能提取正确的 phone 数字。

为什么我要问我的文件是否有效? 因为任何人都可能不小心删除 VLOOKUP 公式,而我无法保护它,因为它是一个使用多个不同宏的共享文档。

是这样的吗? (来源:https://support.microsoft.com/en-us/help/213612/how-to-run-a-macro-when-certain-cells-change-in-excel

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range

    ' The variable KeyCells contains the cells that will
    ' cause an alert when they are changed.
    Set KeyCells = Range("A1")

    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
       Is Nothing Then

    ' Display a message when one of the designated cells has been
    ' changed.
    ' Place your code here.
    Range("B1").Formula = "=VLookup(A1,LookupTable,2,FALSE)"

    End If
End Sub