Я думаю, что вы должны добавить возврат значения в функцию, как уже упоминалось. Вот код:
Public Function DualFindMod(lookupValue1 As String, lookupValue2 As String, lookupRange1 As Range, lookupRange2 As Range) As Range
'Returns selection of lookupRanges based on matching lookupValues.
'A. Set parameters for subroutine arguments
'B. Find & match lookupValues to lookupRanges, then select all matching ranges
'collMatch is the collection of the matching ranges
Dim i As Integer
Dim rngResult As Range
If collMatch.Count > 0 Then
i = 1
Set rngResult = collMatch.Item(1)
Do While i < collMatch.Count
Set rngResult = Union(rngResult, collMatch.Item(i + 1))
i = i + 1
Loop
End If
DualFindMod = rngResult
End Function
Другой вариант - использовать параметры ref:
Public Sub DualFindMod(lookupValue1 As String, lookupValue2 As String, lookupRange1 As Range, lookupRange2 As Range, ByRef rngOutput As Range)
'Returns selection of lookupRanges based on matching lookupValues.
'A. Set parameters for subroutine arguments
'B. Find & match lookupValues to lookupRanges, then select all matching ranges
'collMatch is the collection of the matching ranges
Dim i As Integer
Dim rngResult As Range
If collMatch.Count > 0 Then
i = 1
Set rngResult = collMatch.Item(1)
Do While i < collMatch.Count
Set rngResult = Union(rngResult, collMatch.Item(i + 1))
i = i + 1
Loop
End If
Set rngOutput = rngResult
End Sub
А потом назовите это так:
Dim i As Integer
For i = 1 To GPN.Count
lookupValue1 = GPN.Rows(i).Value
lookupValue2 = Email.Rows(i).Value
Dim rngResult As Range
DualFindMod lookupValue1, lookupValue2, lookupRange1, lookupRange2, rngResult
rngResult.Offset(0, 2).Value = Union(GPN.Rows(i), Email.Rows(i)).Value
Next i