4

I have this function working ( It returns the row where the text DK001 sits in the ID range)

Found = Application.Evaluate("=IF(ID=""DK001"",ROW(ID),""x"")")

I would like to feed the searchcriteria (e.g. DK001) as a string, like

Found = Application.Evaluate("=IF(ID=SearchString,ROW(ID),""x"")")

I fail in creating a string that is accepted as a search criteria. I need your help on this! What am I doing wrong?


This Evaluate function is haunting me ....

What if I now wanted to send a value (not a string) to the function?

Found = Application.Evaluate("=IF(ID=1,ROW(ID),""x"")")

The above works!

But if I want this to be a variable like

Found = Application.Evaluate("=IF(ID=MyValue,ROW(ID),""x"")")

What then?

1
  • 1
    This Evaluate function is haunting me .... What if I now wanted to send a value (not a string) to the function? Found = Application.Evaluate("=IF(ID=1,ROW(ID),""x"")") The above works! But if I want this to be a variable like Found = Application.Evaluate("=IF(ID=MyValue,ROW(ID),""x"")") What then? Commented Feb 27, 2015 at 17:13

3 Answers 3

6

Double " to include them as literals:

SearchString = "DK001"
Found = Application.Evaluate(""=IF(ID=""" & SearchString & """,ROW(ID),""x"")")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It works! I was trying to do the same, but inside the search string, but that failed. Appreciate your help and quick answer!
0

With stdVBA (an open source library largely maintained by myself) you can use stdLambda to accomplish this as follows:

set lambda = stdLambda.Create("if id.value = $1 then id.row else ""x""").bindGlobal("id",range("ID"))
'later...
Found = lambda("DK001")

Comments

-1

Could you try

Application.Evaluate("=IF(ID="" & searchsrtring & "",ROW(ID),""x"")")

2 Comments

Will try this too, wait!
Nope! Get a Error 2029 back on this. But Alex suggestion worked. Thanks to you too for trying to help out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.