I'm trying to call a function and declare it as a variable in my current sub.
I tried changing the declaration to Public but I don't know what the problem is.
I want to declare rngResult to the result of my function
Dim i As Integer
For i = 1 To GPN.Count
lookupValue1 = GPN.Rows(i).Value
lookupValue2 = Email.Rows(i).Value
Dim rngResult As Range
Set rngResult = DualFindMod(lookupValue1, lookupValue2, lookupRange1, lookupRange2)
rngResult.Offset(0, 2).Value = Union(GPN.Rows(i), Email.Rows(i)).Value
Next i
Code of the function
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
End Function