I am using a for loop to create an array containing valid order numbers that will then be used as search criteria for another query table. The next for loop searches for each order number in the previously created array and deletes the row if it is not in the array. I'd like to know why I'm getting a type mismatch error in the conditional statement line of the search function. I tried declaring the array as both a variant and as an array with individual string elements. Here is the trimmed down code, thanks in advanced!
Sub VistaArray()
Dim n As Integer, lastrow As Integer, ordern As String, vista() As Variant
'ADDING NEW ELEMENTS TO ORDER NUMBER ARRAY
For n = 2 To lastrow
i = n - 2
ReDim Preserve vista(i)
ordern = Worksheets(Sheet1).Cells(n, 1).Value
vista(i) = ordern
Next n
'REMOVING LINES FROM SECOND TABLE THAT AREN'T IN THE ARRAY
lastrow = Worksheets(Sheet2).Range("A1").End(xlDown).Row
For n = 2 To lastrow
ordn = ActiveSheet.Cells(n, 1).Value
If IsInArray(ordn, vista) Then
Else
'...REMOVE LINE FROM QUERY TABLE...
End If
Next n
End Sub
Function IsInArray(ordn As String, vista As Variant) As Boolean
IsInArray = (UBound(Filter(ordn, vista)) > -1) '***ERROR OCCURS ON THIS LINE***
End Function
ordn
is a string, not an array.Filter
is expecting an array. Perhaps you need to switch the order of the two arguments toFilter
. – John Colemanvista = Sheet1.Range("A2").Resize(num_rows,1).Value2
, butvista
needs to be defined as two dimensional array. – John Alexiou