【问题标题】:VBA drop downlist onchangeVBA下拉列表onchange
【发布时间】:2017-02-23 18:50:52
【问题描述】:

嘿,我想知道这是否可行:目前我在 sheet1 上有一个下拉列表,其中包含使用数据验证从 sheet2 中提取的名称列表。 该下拉列表旁边的单元格使用 sheet2 中的 VLOOKUP 填充电话号码。
我的问题:我可以使用 VBA 以便每次发生变化在下拉列表中,它旁边的单元格将由 SHEET2 中的数据填充?请记住,选择的值是提取正确电话号码所必需的。

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

【问题讨论】:

    标签: excel onchange vba


    【解决方案1】:

    这样的? (来源: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
    

    【讨论】:

      猜你喜欢
      • 2011-11-03
      • 2016-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多