i automating process work , trying address issues occur in future. part of process import different spreadsheets, employee names , find out manager is. problem faced people known different names on different systems. example, named "donald donaldson" may called "don donaldson" on system, has full name on employee list. alternatively, dave davidison david davidson on system.
this occurs number of times (as people appear 2 times on system list) , slow down entire process while colleagues manually fix issues. address this, created 3 tables/dynamic named ranges on data tab. each table (sample found below) had different purpose; list of wrong names ("names"), list of replacement names ("rep") , alist of names extracted system ("compare"). want through compare list see if there instances of "names" appearing. if finds instance replace name correct one
i feel close achieving needs done, lack moment of brilliance me burst through.
my approach
i have 3 dynamic named ranges (range length change depending on extracted other files) , have stored them 3 dynamic arrays (for reason). code looping through each element in names, each in rep , each in compare. if value in compare (z) equal value in names (x) change value of in rep (so z = y) problem value of z changes, , not corresponding value in array. i.e. don donaldson 3rd element in compare. find match z changed don donaldson donald donaldson. compare(3), however, remains don donaldson.
i have tried making 4th dynamic array, , and using redim increase length of every iteration. every match myarr(index) equal y, , after loop 4th named range ("testrange") set value of array, approach not work either.
is able me? how change value of element in array (compare) , how output new array named range?
my code , sample of data shown below.
pleas help. thanks
sub mysub() dim arr() variant arr = worksheets("data").range("names").value dim comarr() variant comarr = worksheets("data").range("compare").value dim reparr() variant reparr = worksheets("data").range("rep").value dim comint integer comint = 0 dim rowcounter long dim arraycounter long dim x variant dim y variant dim z variant dim zint integer zint = 0 dim myarr() variant each x in arr each y in reparr each z in comarr 'redim myarr(0 zint) variant if z = x z = y 'myarr(zint) = y end if zint = zint + 1 next z next y next x 'worksheets("data").range("testrange").value = comarr() 'worksheets("data").range("testrange").value = myarr() end sub
*my named ranges sorry messy layout
"names" don donaldson, david davidson, mike michaels, pat paterson, steve stevenson, jack jackson, robert robertson, harvey harvie, john johnson
"rep" donald donaldson, dave davidson, michael michaels, patrick paterson, steven stephenson, jak jackson, rob robertson, harv harvie, jon johnson
"compare" don donaldson, mike michaels, jack jackson, john johnson, pat paterson, percy perkins, don donaldson, tom thomson, harvey harvie, mark marcus, kris kristofferson, mitch mitchell, jack jackson, rob robertson
this should comment it's long , i'd provide code you.
i think logic of code wrong... (pseudocode)
if z(don donaldson) = x(don donaldson) >> myarr(?) = don donaldson
and there 55 situation match such comparison. not able check corresponding element in y(donald donaldson)
. either need have parameter match each array (element) or need use key index
not available here. moreover, there different number of elements in each of array. in opinion solve manual work such set of data have.
the check partially suggest try change internal part of loop code:
'...your code here each z in comarr if z = x redim preserve myarr(zint) variant z = y myarr(zint) = y zint = zint + 1 end if next z 'your code here
if additionally change last commented line , uncomment see results:
worksheets("data").range("testrange").value = application.transpose(myarr)
Comments
Post a Comment