I am trying to create a macro that looks through a column of data, and if the value of a cell is #N/A, select the cell that is in the adjacent column. It should keep going down the column until it reaches an empty cell. I believe the most efficient way to do this is to have the macro call a recursive function (I could be very wrong in thinking this I don't have a whole lot of experience with VBA this complex), so that is the route I started to take. However, I keep getting Run-Time error '91': Object variable or With block variable not set. This error occurs on the line with the Union. Again, I am not used to anything this complex so feel free to tell me I'm doing this terribly wrong.
Code:
Function multipleSelect(column As Integer, row As Integer, ws As Object, WorksheetFunction) As CellFormat
If WorksheetFunction.IsNA(Cells(row, column)) Then
Union(ws.Cells(row, column-1)), multipleSelect = (multipleSelect(column, row+1, ws, WorksheetFunction))).Select
ElseIf ws.Cells(row, column).Value <> "" Then
Call multipleSelect(column, row + 1, ws, WorksheetFunction
End If
End Function