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?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Mats Olsson
  • 101
  • 1
  • 2
  • 10
  • 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? – Mats Olsson Feb 27 '15 at 17:13

3 Answers3

6

Double " to include them as literals:

SearchString = "DK001"
Found = Application.Evaluate(""=IF(ID=""" & SearchString & """,ROW(ID),""x"")")
Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • Thanks! It works! I was trying to do the same, but inside the search string, but that failed. Appreciate your help and quick answer! – Mats Olsson Feb 27 '15 at 14:36
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")
Sancarn
  • 2,575
  • 20
  • 45
-1

Could you try

Application.Evaluate("=IF(ID="" & searchsrtring & "",ROW(ID),""x"")")
izzymo
  • 916
  • 1
  • 10
  • 14