excel - Incorporating refedit into Vlookup userform -


i have vlookup userform autofills details in form based on seat n°.

enter image description here

now want incoroporate ref edit paste these data text box cells user chooses refedit. hence need in going these.
this code have used.

potentially want insert 3 refedit boxes user select cell want paste each of data (name,dept , ext no.) textbox.

see code below:

option explicit  private sub frame1_click()  end sub  private sub textbox1_exit(byval cancel msforms.returnboolean)     dim answer integer    answer = textbox1.value    textbox2.value = worksheetfunction.vlookup(answer, sheets("l12 - data sheet").range("b:e"), 2, false)    textbox3.value = worksheetfunction.vlookup(answer, sheets("l12 - data sheet").range("b:e"), 3, false)    textbox4.value = worksheetfunction.vlookup(answer, sheets("l12 - data sheet").range("b:e"), 4, false)  end sub  private sub textbox2_change()  end sub  private sub textbox3_change()  end sub  private sub textbox4_change()  end sub private sub cancelbutton_click()      unload me     end end sub 

i have tried figuring out code solve issue getting object required error. rngcopy textbox2.value (name) , rngpaste location ref edit 1.

this code

private sub pastebutton_click()  dim rngcopy range, rngpaste range dim wspaste range dim answer integer answer = textbox1.value if refedit1.value <> ""          textbox2.value = worksheetfunction.vlookup(answer, sheets("l12 - data sheet").range("b:e"), 2, false)         set rngcopy = textbox2.value         set wspaste = thisworkbook.sheets(replace(split(textbox2.value, "!")(0), "'", ""))         set rngpaste = wspaste.range(split(textbox2.value, "!")(1))          rngcopy.copy rngpaste   else         msgbox "please select output range"     end if end sub 

you should row index match , expose form can used copy function. , set target pointed ref control, evalute .value property range():

range(refedit.value).cells(1, 1) = worksheet.cells(row, column) 

the form:

enter image description here

the code:

' constants define data const sheet_data = "l12 - data sheet" const column_seat = "b" const columnn_name = "c" const column_dept = "d" const column_extno = "e"  private sheet worksheet private rowindex long  private sub txtseatno_change()   dim seatno    'clear fields first   me.txtname.value = empty   me.txtdept.value = empty   me.txtextno.value = empty   rowindex = 0    if len(txtseatno.value)     set sheet = thisworkbook.sheets(sheet_data)      on error resume next      ' seat number either string or double     seatno = txtseatno.value     seatno = cdbl(seatno)      ' row index containing seatno     rowindex = worksheetfunction.match(seatno, _                                        sheet.columns(column_seat), _                                        0)     on error goto 0   end if    if rowindex     ' copy values sheet text boxes     me.txtname.value = sheet.cells(rowindex, columnn_name)     me.txtdept.value = sheet.cells(rowindex, column_dept)     me.txtextno.value = sheet.cells(rowindex, column_extno)   end if end sub  private sub btcopy_click()   if rowindex < 1 exit sub    ' copy current values cells pointed ref controls    if len(me.refname.value) _     range(me.refname.value) = sheet.cells(rowindex, columnn_name)    if len(me.refdept.value) _     range(me.refdept.value) = sheet.cells(rowindex, column_dept)    if len(me.refextno.value) _     range(me.refextno.value) = sheet.cells(rowindex, column_extno) end sub  private sub btlclose_click()   ' close form   unload me end sub 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -