Comparing text in cell with "=text" in another cell with excel VBA -


i trying compare cell values in loop vba. loop using

    each r in rng if cells(r.row, var1) = "string" , cells(r.row, var2) = variable     cells(r.row, var3) = "targetstring1" elseif cells(r.row, var1) = "string2" , cells(r.row, var2) <> variable     cells(r.row, var3) = "targetstring2"  end if next r 

i trying allow inputting conditions input sheet in same excel workbook, need make dynamic. example, in input cells want put "=string" , "<>xx" xx same value variable. allow =/<> controlled input sheet instead of code, , allow more flexibility users adapt conditions situation.

is possible? have tried use evaluate() function, haven't been able work.

any appreciated.

thanks!

test input:

test input

code:

sub tester()      dim rw range      each rw in range("a2:c10").rows         if rw.cells(1) <> ""             rw.cells(3).value = eval(rw.cells(1), rw.cells(2))         end if     next rw  end sub   function eval(rngval range, rngcrit range)      dim addr string, op string     addr = rngval.address(false, false)     op = rngcrit.value      eval = rngval.parent.evaluate(addr & op) end function 

result:

output

when entering criteria may need format cells text or prepend ' prevent excel trying treat formula


Comments