locate exact word in excel VBA -
i have more 1 text word "123" inside textabc
like a123b , c123erf , 123
but wanna locate exact word "123"
text_u1 = mid(textabc, instr(text, "123")) i tried &123& not working
thanks
option explicit sub getword() dim textabc string, s variant, variant, abc string, sz long dim foundstart long, foundlen long textabc = "like a123b , c123erf , 123" abc = "123" s = split(textabc) = 0 ubound(s) sz = sz + len(s(i)) + 1 if trim(s(i)) = abc foundstart = sz - len(s(i)) foundlen = len(textabc) - (sz - len(s(i))) + 1 debug.print "textabc length: " & len(textabc) debug.print "foundstart: " & foundstart debug.print "foundlen: " & foundlen debug.print mid(textabc, foundstart, foundlen) end if next end sub
Comments
Post a Comment