Okay, your criteria / output mapping is different now to your initial example, so we can take the loops out. Function now looks like:
Now, if your MyX, MyY and MyZ variables are in columns E, F and G respectively, then you could write the formula using:
Now, looking at this comment:
'that is the result I get =VLOOKUP(XFC2, Sheet2!P:XFC, lookatcol(MyX,MyY,MyZ), FALSE), guess because I have not set my criteria
I'm guessing you don't really want to be referencing column XFC, so it looks like your relative column references aren't quite what you wanted....
It's quite hard to provide a specific solution without a specific example outcome to work towards!
Bookmarks