Trouble confirming whether a value in one array is in another.

TheRedCardinal

Board Regular
Joined
Jul 11, 2019
Messages
243
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
This is a continuation of the this thread:


I've managed to get the check working, however I am always getting "False" back from the function even when there is a definite match.

Here is my code:

VBA Code:
Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
  IsInArray = Not IsError(Application.Match(stringToBeFound, arr, 0))
End Function

VBA Code:
CustomerData = WS3.ListObjects(1).DataBodyRange

'Check Customer Entry is correct

If ExportArray(UBound(ExportArray), 6) <> "" Then

    SearchStr = ExportArray(UBound(ExportArray), 6)

    If IsInArray(SearchStr, CustomerData) = False Then
        MsgBox ("Customer Not Found")
    Else
        MsgBox ("Customer Found")
    End If

End If

I must be mixing something up somewhere - what have I done wrong?

Thanks!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I am not sure whether that is possible, but one possible work around could be using .Find, since you're just looking at the table range

VBA Code:
Dim f As Range

'Check Customer Entry is correct

If ExportArray(UBound(ExportArray), 6) <> "" Then

    SearchStr = ExportArray(UBound(ExportArray), 6)
    
    Set f = ws3.ListObjects(1).DataBodyRange.Find(SearchStr, lookat:=xlWhole, LookIn:=xlValues)
    If f Is Nothing Then
        MsgBox ("Customer Not Found")
    Else
        MsgBox ("Customer Found")
    End If

End If
 
Upvote 0
Solution

Forum statistics

Threads
1,214,869
Messages
6,122,012
Members
449,060
Latest member
LinusJE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top