excel - VBA- Iterating through string values in an array and identifying if they are equal to a specific text -
i have data set in excel lot of columns. i'm using userform entry populate columns. want able write existing id in userform , autopopulate useform corresponding data being pulled spreadsheet. order of columns might change, don't want use offset function this.
what i'm trying in code make array column names (it's corresponding text boxes in entry form named same).
first, i'm finding row id. want iterate through different columns , find values under them correspond id populate entry form.
the problem want use "array(i)" name of text box in userform doesn't read it. example:
if directly write mrn = cells(csn_r, changing_c), populate entry form right data, selects id row , column number under "mrn" or "myarray(0)". if use myarray(0) =cells(csn_r, changing_c) doesn't.... don't know make work.
dim csn_find range dim csn_existing range dim csn_new range dim csn_r integer dim changing_c integer ' csn value worksheets("input data").activate worksheets("input data").rows(1).find(what:="csn", lookin:=xlvalues).entirecolumn.select set csn_find = selection.find(what:=csn.value, lookin:=xlvalues, lookat:=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:=false) ' if it's found, populate form if (not csn_find nothing) csn_find.activate csn_r = activecell.row dim myarray variant dim integer dim lastcolumn integer myarray = array("mrn", "arrivaldate",...(i have lot)) lastcolumn = worksheets("input data").cells(1, columns.count).end(xltoleft).column = 0 until = lastcolumn + 1 changing_c = worksheets("input data").rows(1).find(what:=myarray(i), lookin:=xlvalues, lookat:=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:=false).column myarray(i) = cells(csn_r, changing_c) **** not working = + 1 loop ' else, nothing: else: if csn_find nothing exit sub end if end sub
when use myarray(i) = cells(csn_r, changing_c) **** not working
you're overwriting array values
it looks you're trying assign text userform control textbox. should able refer textbox via userform name - called?
say it's default "userform1" can use:
userform1.controls(myarray(i)).text = cells(csn_r, changing_c)