Option Explicit
Sub CombineData()
Dim myInput As Range
Dim myOutput As Range
Dim inputTwoValues As Collection
Dim output1 As Collection
Dim output2 As Collection
Dim anOutput1 As Variant
Dim anOutput2 As Variant
Set myInput = Worksheets("Sheet1").Range("A1")
Set myOutput = Worksheets("Sheet3").Range("A1")
Do
Set output1 = GetRelatedValues(myInput.Value)
Set output2 = GetRelatedValues(myInput.Offset(0, 1).Value)
For Each anOutput1 In output1
For Each anOutput2 In output2
myOutput.Formula = anOutput1
myOutput.Offset(0, 1).Formula = anOutput2
Set myOutput = myOutput.Offset(1, 0)
Next
Next
Set myInput = myInput.Offset(1, 0)
Loop While myInput.Value <> ""
End Sub
Function GetRelatedValues(myInput As Variant) As Collection
Dim returnVal As New Collection
Dim myRelationship As Range
Set myRelationship = Worksheets("Sheet2").Range("A1")
While myRelationship.Value <> ""
If myRelationship.Value = myInput Then
returnVal.Add (myRelationship.Offset(0, 1).Value)
End If
Set myRelationship = myRelationship.Offset(1, 0)
Wend
Set GetRelatedValues = returnVal
End Function