[英]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.