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

TheRedCardinal

Board Regular
Joined
Jul 11, 2019
Messages
169
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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

aRandomHelper

Active Member
Joined
Jan 14, 2021
Messages
278
Office Version
  1. 2016
Platform
  1. Windows
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
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,129,301
Messages
5,635,406
Members
416,856
Latest member
silentir

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
Top