Function If 2 array = value

Infine

Board Regular
Joined
Oct 16, 2019
Messages
93
Office Version
  1. 365
Platform
  1. Windows
Hello,

So I have created an array with 2 values in it SEE: KMyarray = Application.Transpose(Range(rngArray1, rngArray2))
In my other variable I have StrLookForString = <code here> (see below).

I want to see if the value in MyArray1 and the value in MyArray2 = StrLookForString .

So basically
MyArray(1) & MyArray(2) = Variable


How do I do this? See some of the code below:


VBA Code:
Set rngArray1 = Range(Sheets("Köpunderlag").Range("B2"), Sheets("Köpunderlag").Range("B2").End(xlDown))
Set rngArray2 = Range(Sheets("Köpunderlag").Range("G2"), Sheets("Köpunderlag").Range("G2").End(xlDown))

KMyarray = Application.Transpose(Range(rngArray1, rngArray2))


 StrLookForString = Sheets("OFIC Köp").Cells(i, 5) & Sheets("OFIC Köp").Cells(i, 12)
        BoolHit = FindLoop(KMyarray, StrLookForString)

If BoolHit = True Then
SomeCodeHere
Else
Something else


And this is the function which is not working - my guess:


VBA Code:
Function FindLoop(arr, val) As Boolean
' Function to find matching value in array.
    Dim r As Long
    For r = 1 To UBound(arr, 1)
        If CStr(arr(r, 1)) & CStr(arr(r, 2)) = val Then
            FindLoop = True
            arr(r, 1) = "OK"
            arr(r, 2) = "OK"
            Exit Function
        End If
    Next r
End Function

This is what is not working (my guess): If CStr(arr(r, 1)) & CStr(arr(r, 2)) = val Then


Would really appreciate if anyone can help me, I am stuck here.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
This line
VBA Code:
If CStr(arr(r, 1)) & CStr(arr(r, 2)) = val Then
should be
VBA Code:
If CStr(arr(r, 1)) =val And CStr(arr(r, 2)) = val Then
But your KMyarray will be 6 columns of data not 2, so that will be looking at col B & col C
 
Upvote 0
VBA Code:
If CStr(arr(r, 1)) = val And CStr(arr(r, 2)) = val Then

Did not work.

I can explain in words what the variables are:
KMyarray(1) = LU193329292
KMarray(2) = 3403,32

StrLookForString = LU1933292923403,32

(So StrlLookForString is Kmarray1 and 2 together).

And I want to "If it's true, then write code. Else. Write some other code here.
 
Upvote 0
Ok, as you are concatenating them, then your code was correct, other than your possibly looking at the wrong columns.
 
Upvote 0
Which one was correct, the one you gave me or the initial that I gave you? I don't seem to make it work. It doesn't say it is correct. They do not match.

Whenever If BoolHit = True Then runs it doesn't give the correct values.
 
Upvote 0
Your version was correct, but you are probably looking at the wrong columns.
 
Upvote 0
I tested the code now, and it is not correct.

KMyarray(1) = LU193329292
KMarray(2) = 3403,32

StrLookForString = LU1933292923403,32

The
VBA Code:
If CStr(arr(r, 1)) & CStr(arr(r, 2)) = val Then

Makes LU193329292 & LU193521701 = val

But it should be

LU193329292 & 3403,32 = val


so if all


MkArray(1) MkArray(2)
LU193329292 3403,32
LU193521701 5552,142


It takes only from MkArray(1)
 
Upvote 0
Have you actually read any of my posts? I have made the same observation in them all & you seem to have totally ignored it.
 
Upvote 0
Okey I apologize, I didn't understand :) But I see now. It's 1, r instead of r, 1. Thank you for your help once again!
 
Upvote 0
Your array is getting data from columns, B, C, D, E, F & G, not just columns B & G.
As I cannot see your data this is a guess, but try
VBA Code:
       If CStr(arr(1, r)) & CStr(arr(6,r)) = val Then
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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