Create a module in your workbook and add the following code:
Public Sub copyInfo()
On Error Resume Next
'#
'# declare private variables
'#
Dim strLookupKey As String
Dim strExtraInfo As String
Dim objFound As Excel.Range
'#
'# assuming sheet1 is the input worksheet containing cell A1 and A2 as per
'# your example
'#
With ThisWorkbook.Worksheets("Sheet1")
strLookupKey = .Range("A1").Value
strExtraInfo = .Range("A2").Value
End With
'#
'# search for the lookup_value in the data worksheet, assuming the data worksheet is called
'# Sheet2 and the search must be performed in column C - using the column layout as described
'# in your post
'#
With ThisWorkbook.Worksheets("Sheet2")
'#
'# conduct a search; when the search argument is found, the objFound range object will contain a pointer
'# to the cell in column C holding the argument searched - you can play with the parameters to make the
'# search more or less restrictive (match case, whole or partial cell value matching etc)
'#
Set objFound = .Cells.Find(What:=strLookupKey, After:=Cells(1, "C"), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False)
'#
'# if the search text was found, the target column (extra info) can be updated with the extra info provided in
'# cell A2 - the cell to update can be found by moving two columns to the right from the cell holding the found
'# search argument
'#
If Not objFound Is Nothing Then
objFound.Offset(0, 2).Value = strExtraInfo
Else
MsgBox "Sorry but the name " & Chr$(34) & strLookupKey & Chr$(34) & " could not be found"
End If
End With
End Sub
Add a button object to your first worksheet and subsequently link the button to the above routine - change the names of the worksheets in the code provided to meet your requirements
Bookmarks