Excel数据验证列表 - 不同的显示数据与结果数据

问题描述 投票:0回答:1
我甚至无法开始思考我需要做的事情。我已经完成了vlookup的操作,您在一个单元格中的下拉列表中更改了一件事情,并且旁边的单元格的数据发生了变化,但是我正在寻找它在同一单元格中。

是的,您只需一个普通列表/验证 + vba。

设置您的验证值(名称列表)。与掉期(缩短名称)搭配

excel validation drop-down-menu
1个回答
0
投票

    data->使用list
  1. 验证

  2. 对于床单,附加VBA(下面我的简短测试)

  3. 观看数据条目表上的正确列

  4. 事件,将输入值与替换值交换

    1. 唯一的收获是您的VBA会触发自身:该函数会更改单元格值,该函数会触发单元格更改事件,从而触发相同的功能等。在下面,我通过设置标志破坏了该循环,但可能还有其他解决方案。

    2. Public DisabledFlag As Boolean Private Sub Worksheet_Change(ByVal Target As Range) Dim KeyCells As Range Dim NewValue As Variant If DisabledFlag = True Then DisabledFlag = False GoTo Disabled End If ' The variable KeyCells contains the cells that will ' cause an alert when they are changed. Set KeyCells = Range("D4:D12") If Not Application.Intersect(KeyCells, Range(Target.Address)) _ Is Nothing Then ' Use the current value to get the 'real' value ... On Error Resume Next NewValue = WorksheetFunction.XLookup( _ Target.Value, _ Range("A4:A6"), _ Range("B4:B6"), _ "Not found") On Error GoTo 0 ' Setting the value will trigger this function ... ' Ignore that event. DisabledFlag = True Target.Value = NewValue End If Disabled: End Sub

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.