Reputation: 5
Excuse my lack of coding language, I'm just getting into vba coding. 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.
Worksheet "SPECSHEET" is fully created from macro.
Worksheet "CONTACTS" has a list of names in column A and phone numbers in column C
Worksheet "DATASHEET" holds information about each luminaire.
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.
Upvotes: 0
Views: 6179
Reputation: 152450
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. If it is not found then it returns Not Found
.
Upvotes: 1