string - Error 13 VBA in simple find and replace -


i new @ programmming, sorry if question boring.

i trying create macro checks string "meh" in range of cells , substitutes cell above "blahblah"

so far code:

sub findandreplace()   dim e string, wide range, r range  e = "meh"  set wide = range("a1:cm300")  each r in wide      if instr(r.value, "meh") > 0         r.offset(-1, 0).value = "blahblah"  end if 

it worked first time run it, gives me error type 13 in if sentence. know have dim something, don´t know what.

thanks help!

no dont have dim anything. way variable names terrible.

you type mis match error when cell value error (like #n/a, #div/0!)

check in code iserror

sub test() dim e string, wide range, r range  e = "meh"  set wide = range("a1:cm300")  each r in wide      '/ check if cell contains error.     if not iserror(r)         if instr(r.value, e) > 0             r.offset(-1, 0).value = "blahblah"         end if     end if next   end sub 

Comments