excel - Want to write formula in cell if x=y, otherwise blank cell, using VBA -


let me better explain. if value of a1 "0" in a2 want formula =vlookup(b1,c1:e3,2,0), if value of a1 "1", want blank cell value a2. want macro occur upon opening excel. thought work not

sub test()      dim indicator value     dim result string      indicator = range("a1").value      if indicator = 0 result = "=vlookup(a3,c1:d3,2,0)"      range("a2").value = result  end sub 

in thisworkbook section put in

sub workbook_open()  if range("a1") = 0     range("a2").formula = "=vlookup(b1,c1:e3,2,0)" elseif range("a1") = 1     range("a2").clearcontents else end if  end sub