Problem: I am comparing two columns of names. If a name from the primary column matches a name in the secondary column, then I would like to add the matching name to an array of strings.
Function 1: This boolean function should indicate whether there is a match:
Function Match(name As String, s As Worksheet, column As Integer) As Boolean
Dim i As Integer
i = 2
While s.Cells(i, column) <> ""
If s.Cells(i, column).Value = name Then
Match = True
End If
i = i + 1
Wend
Match = False
End Function
Function 2: This function should add the matching name to a dynamic array of strings. Here I am somewhat stuck as I am new to arrays- any suggestions?
Function AddToArray(ys) As String()
Dim a() As String
Dim size As Integer
Dim i As Integer
Dim sh As Worksheet
Dim rw As Range
size = 0
ReDim Preserve a(size)
For Each rw In sh.Rows
If Match(sh.Cells(rw.Row, 1), s, column) = True Then
??
size = size + 1
End Function
Matchfunction, in theAddToArrayfunction, you are calling it with the parametersbut you have declared the worksheet as variable namesh, which you have not initialized to anything. You also are calling it with the parametercolumnwhich hasn't been declared and hasn't been initialized, so this statement won't work.Matchfunction won't work. As written, it will always returnFalsebecause it will get through theWhileloop and then automatically get set toFalse. You need to put theMatch=Falsestatement at the BEGINNING of the function if you want to do it this way.