excel vba - vlookup splitted through items does not work -


one time, asked on function vlookup split value. using long time. now, code no longer seems work. can reason code working no longer does?

sub test() dim cl range, key variant dim dic object: set dic = createobject("scripting.dictionary") dic.comparemode = vbtextcompare sheets("sheet1")     each cl in .range("a1:a" & .cells.specialcells(xlcelltypelastcell).row)         if cl.value <> ""             dic.add cl.row & "|" & replace(lcase(cl.value), ";", "||") & "|", cl.offset(, 1).text         end if     next cl end with sheets("sheet2")     each cl in .range("a1:a" & .cells.specialcells(xlcelltypelastcell).row)         each key in dic             if key "*|" & lcase(cl.value) & "|*" , cl.value <> ""                 cl.offset(, 1).value = dic(key)                 exit             end if         next key     next cl end end sub 

at moment there no errors code not working. people working. me not. please see expected result below:

enter image description here

i felt need refactor code because posted answer on how wildcard search of dictionary.

could edit answer include sample data column of sheet1 & sheet2?

sub refactoredcode()      dim cl range     dim key, keys, results     dim matchstring string      dim dic object: set dic = createobject("scripting.dictionary")     dic.comparemode = vbtextcompare      sheets("sheet1")         each cl in .range("a1", .range("a" & rows.count).end(xlup)).specialcells(xlcelltypevisible)              dic.add cl.row & "|" & replace(lcase(cl.value), ";", "||") & "|", cl.offset(, 1).text          next cl     end      keys = dic.keys      sheets("sheet2")         each cl in .range("a1", .range("a" & rows.count).end(xlup)).specialcells(xlcelltypevisible)          matchstring = "|" & lcase(cl.value) & "|"             results = filter(keys, matchstring, true, vbtextcompare)              if ubound(results) > -1                 key = results(0)                 cl.offset(, 1).value = dic(key)             end if          next cl     end  end sub 

i ran both refactoredcode() , test(). both of them working properly.

enter image description here


Comments

Popular posts from this blog

Lists in Python -

android - can not access to progress bar in an other activity -

html - Not able to access next element of an array javascript -