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

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -