I have an array with orders (order date, customer etc) and I need to check whether a specific ID corresponds to a customer.
Here is the function / data below:
If I use CheckCustomer(108,723) I get FALSE - even though the customer is clearly in the table with the correct ID.
As I am working with array data, I was wondering whether the
return 'true' value is overwritten as soon as a 'false' is found in the array.
Is there any other way to search for these value, like with SUMPRODUCT?
Thanks for your help.
Maria
[TABLE="width: 183"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Customer[/TD]
[/TR]
[TR]
[TD]108[/TD]
[TD]723[/TD]
[/TR]
[TR]
[TD]159[/TD]
[TD]723[/TD]
[/TR]
[TR]
[TD]490[/TD]
[TD]723[/TD]
[/TR]
[TR]
[TD]292[/TD]
[TD]723[/TD]
[/TR]
[TR]
[TD]381[/TD]
[TD]723[/TD]
[/TR]
</tbody>[/TABLE]
Here is the function / data below:
Code:
Function CheckCustomer(ID As Integer, Customer As Integer) as Boolean
Dim arr() As Variant
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Orders")
arr = ws.Range("tblOrders")
Dim i As Long
'Check if the customer does have such a contract
For i = 1 To UBound(arr)
If arr(i, 2) = Customer And arr(i, 1) = ID Then
CheckCustomer = True
Else
CheckCustomer = False
End If
Next i
End Function
If I use CheckCustomer(108,723) I get FALSE - even though the customer is clearly in the table with the correct ID.
As I am working with array data, I was wondering whether the
return 'true' value is overwritten as soon as a 'false' is found in the array.
Is there any other way to search for these value, like with SUMPRODUCT?
Thanks for your help.
Maria
[TABLE="width: 183"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Customer[/TD]
[/TR]
[TR]
[TD]108[/TD]
[TD]723[/TD]
[/TR]
[TR]
[TD]159[/TD]
[TD]723[/TD]
[/TR]
[TR]
[TD]490[/TD]
[TD]723[/TD]
[/TR]
[TR]
[TD]292[/TD]
[TD]723[/TD]
[/TR]
[TR]
[TD]381[/TD]
[TD]723[/TD]
[/TR]
</tbody>[/TABLE]