Macro to remove duplicate values from an excel cell -
i have duplicate email ids in excel cell. (each cell has around 5 6 emails repeated below). there macro remove unique ones cell ? have given example below reference, appreciate assistance.
cell 1 abc@cc.com cde@bb.com abc@cc.com lmn@nn.com cde@bb.com cell 2 jjj@cc.com kk@dd.com jjj@cc.com auro
i used data in blank worksheet in column a, , output gets put in column b. can change loops , cell references suit needs. i've assumed want email addresses contained in cell remain grouped (once duplicates have been removed) in output.
this code assumes email addresses separated 'carriage return'
sub removeduplicate() 'references: http://stackoverflow.com/questions/3017852/vba-get-unique-values-from-array dim wks worksheet dim rng range dim wordcount integer dim d object dim integer dim j integer dim v variant dim outtext string set wks = worksheets("sheet1") '<- change sheet suit needs j = 1 2 '<- change loop suit needs set rng = wks.range(cells(j, 1), cells(j, 1)) '<- change cell reference required set d = createobject("scripting.dictionary") 'use carriage return (chr(10)) 'find' text 'count words/email addresses wordcount = len(rng) - len(replace(rng, chr(10), "")) + 1 'split words carriage return arrwords = split(rng, chr(10)) = 0 wordcount - 1 d(arrwords(i)) = 1 next 'create output text re-grouping split text. outtext = "" each v in d.keys if outtext = "" outtext = v else outtext = outtext & chr(10) + v end if next v 'output adjacent cell rng.offset(0, 1).value = outtext set d = nothing next j set wks = nothing end sub
Comments
Post a Comment