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