vba - If TextBox1.Text found in A:A, add TextBox2.Text to later cell in that row -


i have userform entering translations. there textboxes title (txttitle), text translate (txttotranslate) , translated text (txttranslation) , combobox select language (cbolanguage).

the code creates new row of data each time user clicks submit. modify functionality follows:

1 clicking submit, check if txttitle exists in a:a

2a if txttitle not exist, create new row (current functionality)

2b if txttitle exists, add txttranslation row txttitle, rather "nextrow"

    private sub btnsubmit_click()      dim findstring string     dim rng range      findstring = "*" & txttitle      if trim(findstring) & "*" <> ""         sheets("output").range("a:a")             set rng = .find(what:=findstring, _                     after:=.cells(.cells.count), _                     lookin:=xlvalues, _                     lookat:=xlwhole, _                     searchorder:=xlbyrows, _                     searchdirection:=xlnext, _                     matchcase:=false)             if not rng nothing                 ????                                     else                 sheets("output").activate                 nextrow = application.worksheetfunction.counta(range("a:a")) + 1                     cells(nextrow, 1) = txttitle.text                     cells(nextrow, 2) = txttotranslate.text                                               if cbolanguage = "fr-fr" cells(nextrow, 3) = txttranslation.text                         if cbolanguage = "it-it" cells(nextrow, 4) = txttranslation.text                         if cbolanguage = "de-de" cells(nextrow, 5) = txttranslation.text                         unload frmnewtranslation             end if         end     end if     end sub 

here how go it:

dim rng range dim findstring string  findstring = "*" & trim(txttitle) & "*" 'this match occurance of txttitle in target cell  set rng = range("a1") 'set starting range cell  while rng.value <> ""      if rng.value findstring          'your code update current row here          exit sub     end if      set rng = rng.offset(1, 0)  'offset cell down 1  wend  'your code create new row here. rng positioned @ next empty cell 

does help? short explanation of happening (to along way):

first set range variable topmost cell want search (a1 in case). enter loop: if checks see if value of rng matches findstring and, if so, can put code in there whatever needs done when match found. if no match found in row if block doesn't execute, , rng gets set cell below (dropping down one), , loop repeats. loop run until first blank cell found, assumes there no blanks in column. @ moment blank cell found, loop ends , code continues. however, rng set blank cell, create new row so:

rng.value = 'whatever rng.offset(0, 1).value = 'next column whatever rng.offset(0, 2).value = 'third column whatever 

and on.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -