Excel/VBA lookup


Im looking for some help using VBA.
I have a list of projects with peoples names at the side on "sheet1". (each project can have a max of 4 names at the side)

on a second sheet i have the same list of projects with the time resource that it will require to complete them on a year calendar

on a third sheet i have a list of all the potential names and a year calendar.

If a name is next the project, i would like to copy the data time resource from teh second sheet, find the name on the third sheet and past it.

The section of my code i am struggling with is identfying a name on the first spreadsheet and finding it again on third sheet. Any advice as to which function i could use to achieve this would be much aprreciated.



This macro will loop through names in A1:A4 of sheet 1 and then use the Find command to find an identical name on sheet3.  If such a name is found, it places the name in Sheet1 next to the name in Sheet3.  Obviously you would not two identical names next to each other - I am just doing that to illustrate how the code would work.  You would modify it to accomplish what you want to do.  

Sub Macro1()
Dim rng As Range, cell As Range
For Each cell In Worksheets("Sheet1").Range("A1:A4")
' cell is a reference to one of the cells in the range A1:A4 on sheet1
' that contain a name to search for on sheet3
Set rng = Worksheets("Sheet3").Cells.Find(What:=cell.Text, _
After:=Worksheets("Sheet3").Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
If rng Is Nothing Then  ' if rng is nothing, then the name was not found
 ' the item was not found
 cell.Copy rng.Offset(0, 1)
End If
End Sub

The code was tested and does what I described.  Probably want to test anything you derived form this on a copy of your workbook.

Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Tom Ogilvy


Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]


Extensive experience.

Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2017 About.com. All rights reserved.

[an error occurred while processing this directive]