VBA Compute function with string arguments

This function works for me (it returns a string where the text DK001 is in the range of ID)

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

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

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

I cannot create a string accepted as a search term. I need your help! What am I doing wrong?


This Evaluate feature is haunting me ....

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

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

The above work!

But if I want it to be a type variable

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

What then?

+2
source share
2 answers

Double "to include them in the number of literals:

SearchString = "DK001"
Found = Application.Evaluate(""=IF(ID=""" & SearchString & """,ROW(ID),""x"")")
+4
source

Could you try

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

Source: https://habr.com/ru/post/1674036/


All Articles