In my code, I've declared a variable "Warranty Code" as a variant, and then populated that variant as an array with 41 potential 2 character string values.
Now I'm looping through a range, and checking each cell in that range (the "MWWar" variable), to see if it matches one of the 41 strings in my array.
If it does, I want my code to do nothing, but if it doesn't, I want it to add one to my counter (the "BadWar" variable).
If the "WarrantyCodeFilter" variable does match, the code works fine and does nothing but go onto the next line. However, if it doesn't find a match in my array, it becomes "subscript out of range" error 9, and won't let me proceed.
I've tried the "If(Iserror) = true" to add to my counter, but it still wouldn't let me do it
How can I get the no match scenario to just add to my counter, and move on to the next line instead of erroring out?
For i = 2 To lr
Set MWWar = Cells(i, MWWarCol)
WarrantyCodeFilter = Filter(WarrantyCode, MWWar, True, vbTextCompare)
If IsError(WarrantyCodeFilter(0)) = True Then BadWar = BadWar + 1
Next i
WarrantyCodeFilterwon't throw an error. Per documentation: "The array returned by the Filter function contains only enough elements to contain the number of matched items."Filteralso matches on substrings, so you'll need a different approach if you want an exact match.Match()against the range (you could use Match against the array, but it would be slower than against the range). If you only have them as an array then a simple loop to check each element would be fine.