简体   繁体   English

VBA如何匹配单元格与相邻单元格的范围和返回值?

[英]vba how to match cell with range and return value in adjacent cells?

Excuse my lack of coding language, I'm just getting into vba coding. 对不起我缺乏编码语言,我只是进入vba编码。 I have a list of Manufacturers (names) with contact details on one that I like to be populated on my "SPECSHEET" automatically when choosing manufacturer. 我有一个制造商(名称)列表,上面有联系方式,我希望在选择制造商时自动在“ SPECSHEET”上填写这些信息。

Worksheet "SPECSHEET" is fully created from macro. 工作表“ SPECSHEET”是完全从宏创建的。

Worksheet "CONTACTS" has a list of names in column A and phone numbers in column C 工作表“联系人”在A列中有一个名称列表,在C列中有一个电话号码

Worksheet "DATASHEET" holds information about each luminaire. 工作表“ DATASHEET”包含有关每个灯具的信息。

I am successful in showing the right manufacturer name: 我成功显示了正确的制造商名称:

Worksheets("SPECSHEET").Cells(Company, 5).Value = Worksheets("DATASHEET").Cells(1, 5).Value

But I like the row below to show the phone number: 但我喜欢下面显示电话号码的行:

If Worksheets("SPECSHEET").Cells(3, 4).Value = Worksheets("CONTACT").Range(A:A).Value Then
Worksheets("SPECSHEET").Cells(3, 5).Value = Worksheets("CONTACT").Cells(B "name adjacent to the matched name in column A) 
End If

Thanks for any help. 谢谢你的帮助。

Try this: 尝试这个:

Dim t
t = Application.Match(Worksheets("SPECSHEET").Cells(3, 4).Value, Worksheets("CONTACT").Range("A:A"), 0)
If Not IsError(t) Then
    Worksheets("SPECSHEET").Cells(3, 5).Value = Worksheets("CONTACT").Range("B" & t)
Else
    Worksheets("SPECSHEET").Cells(3, 5).Value = "Not Found"
End If

It uses the worksheet function MATCH() to find the row and then returns the value in Column B of that row. 它使用工作表函数MATCH()查找行,然后返回该行的B列中的值。 If it is not found then it returns Not Found . 如果找不到,则返回Not Found

暂无
暂无

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

相关问题 Excel使用一系列单元格返回与相邻单元格对应的值 - Excel using a range of cells to return value corresponding to an adjacent cell 在VBA中使用Worksheet_Change事件,带范围,如果值为空,如何返回相邻单元格的值 - Using Worksheet_Change event in VBA, with a range, how to return value of adjacent cell if value is nothing Excel VBA如何将WorkSheet名称与单元格值匹配,然后复制并粘贴一系列单元格 - Excel VBA How to match WorkSheet name with Cell value, then Copy and Paste a Range of Cells EXCEL:需要在另一个工作表的单元格范围内查找值,并从相邻单元格返回值 - EXCEL: Need to find a value in a range of cells from another worksheet and return value from adjacent cell VBA/Excel - 如果相邻单元格的值匹配,则添加单元格值 - VBA/Excel - Adding cell values if values of adjacent cells match VBA:如何在单元格范围内搜索值,然后返回该位置旁边的单元格? - VBA: How to search range of cells for value, and return the cells next to the location? 合并与活动单元格 VBA 相邻的单元格中的两个单元格的值 - Combine the value of two cells in the cell which is adjacent to Active cell VBA 如果找到匹配项,则将单元格中的值与复制相邻单元格的范围中的值进行比较 - Comparing a value in a cell to values in a range copying adjacent cell if match is found 在工作表中搜索单元格值,然后将相邻单元格复制到变量范围中 - Search a worksheet for a cell value, then copy the adjacent cells into a variable range 根据相邻像元值锁定行中像元的范围 - Lock range of Cells in row based on adjacent cell value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM