简体   繁体   English

如何在Excel中填充两个命名范围中的单元格值?

[英]How can I fill cell values from two named ranges in excel?

I have two named ranges 我有两个命名范围

range 1 : test1, test2, test3, test4 范围1:test1,test2,test3,test4

range 2 : 20, 30, 50, 80 范围2:20,30,50,80

If I select one of the values from range 1, then the corresponding range 2 value should be copied to next cell. 如果我从范围1中选择一个值,则应将对应的范围2值复制到下一个单元格。 For example, if I select 'test 3' from dropdown, then text '50' should be copied to adjacent cell. 例如,如果我从下拉列表中选择“测试3”,则应将文本“ 50”复制到相邻的单元格中。

From the OP's comments below: 从以下OP的评论中:
Sheet 2 has two named ranges - range 1 and range 2. In sheet 1, First column is assigned 'range 1'. 工作表2有两个命名范围-范围1和范围2。在工作表1中,第一列分配为“范围1”。 If I select one of the values from range 1, then the adjacent cell should have corresponding 'range 2' value. 如果我从范围1中选择一个值,则相邻单元格应具有相应的“范围2”值。

This should be all you need. 这应该是您所需要的。

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) = "B3" Then
        Application.EnableEvents = False
        Target.Offset(0, 1) = Range("range2") _
            (Application.Match(Target.Value, Range("range1"), 0))
        Application.EnableEvents = True
    End If
End Sub

This formula finds the drop down text in range1 and recalls that location in range2. 此公式在range1中找到下拉文本,并调出range2中的该位置。

Replace A1 with location of drop down selection. 将A1替换为下拉选择的位置。

Assumptions: Both arrays are of equal length. 假设:两个数组的长度相等。

=IFERROR( INDEX( range2, MATCH(D2, range1)), "•")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel我如何替换命名范围的标签以在公式中访问其值 - Excel How can i substitute labels of named ranges to access their values in a formula VBA Excel-如何将工作簿B中命名范围的值转换为工作簿A中相同/相似的命名范围? - VBA Excel - How to transfer Values of Named Ranges from Workbook B into same/similar Named Ranges in Workbook A? excel 2003:如何从单元格引用命名范围? - excel 2003: How can I reference a named range from a cell? Excel VBA:如何在同一列中交换两个选定的单元格区域(不仅两个值)? - Excel VBA: How to swap two selected cell ranges (not only two values) within the same column? Excel在多个命名范围中搜索单元格匹配 - Excel Search for cell match in multiple named ranges Excel - 将单元格值插入范围 - Excel - Inserting Cell Values into Ranges 如何在Excel中将图表扩展一定的月数,包括命名范围? - How can I extend a chart in Excel by a certain amount of months including named ranges? 如何将Excel中的所有命名范围导出到单独的CSV文件? - How can I export all named ranges in Excel to Separate CSV files? 如何根据旁边单元格中的值在excel中为单元格着色? - How can I colour a cell in excel based on the values in the cell next to it? 如何获取我的所有 Excel 命名范围的列表 - How do I get a list all of my Excel Named Ranges
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM