MM, your problem would be ideally suited to do with database software, such as Microsoft Access. Otherwise, you'd need VBA (Visual Basic for Applications) code to do it in Excel. I wrote some code (to brush up on my VBA for Excel skills) - the problem is there's a million ways to do it, and I'm not at all sure my solution is the simplest and/or best suited for what you're doing. (Actually, it's a bit overly complex at the moment.) But it works.
I'm posting it here for you to play with, but I can make adjustments for you tomorrow (and explain how to use it if need be):
Sub findfill() Dim mySheet As Worksheet Dim r As Range Dim rKey As Range Dim i As Integer Dim rLkup As Range Dim rDest As Variant Set mySheet = Worksheets("Sheet1") 'manually set the range to run this program against: Set r = mySheet.Range("a2", "a14") For i = 1 To r.Cells.Count If r(i) = "" Then Set rKey = Cells(r(i).Row, r(i).Column + 1) r(i).Value = rKey Set rLkup = LookupKey(rKey.Value) If rLkup Is Nothing Then 'do nothing - no match found Else Set rDest = Range(Cells(r(i).Row, r(i).Column + 2), Cells(r(i).Row, r(i).Column + 4)) rLkup.Copy (rDest) End If End If Next i End Sub
Private Function LookupKey(vIn As Variant) As Range Dim r2 As Range Dim rRet As Range Dim i As Integer Dim lkupsht As Worksheet Set lkupsht = Worksheets("Sheet2") 'manually set the range for the lookup data to be used: Set r2 = lkupsht.Range("a1", "a10") For i = 1 To r2.Cells.Count If r2(i) = vIn Then Set rRet = Worksheets("Sheet2").Range(lkupsht.Cells(r2(i).Row, r2(i).Column), lkupsht.Cells(r2(i).Row, r2(i).Column + 2)) Set LookupKey = rRet Exit For End If Next i End Function
You'd have to customize it for the range you're running this against and the range of the data on sheet 2 you're looking up. I put comments (i.e. the lines preceded by a ') before the lines you'd need to adjust. Also not that it expects the two sheets to be called "Sheet1" and "Sheet2".
'findfill()' is the subroutine that you'd actually run.