vba - Code Interruption Error -


so code have below attempts find wip in column h. if find wip: copy 3 cells , make 10 replicas of them in next column either in same row or next available row.

for reason code runs loop first "wip" value , gives code interruption error. can see why keeps happening?

thank you, ori

sub step1_update()  dim dblsku double dim strdesc string dim strtype string dim browfin integer dim browfin1 integer dim counter integer dim trowfin integer  counter = 0  worksheets("final").activate  trowfin = 5 browfin = activesheet.range("a" & rows.count).end(xlup).row  'loop 1 while trowfin < browfin      'if 1 (set 3 values)     if range("h" & trowfin).value = range("h3").value           dblsku = range("f" & trowfin).value          strdesc = range("g" & trowfin).value          strtype = range("h" & trowfin).value           'find last used row in col j          browfin1 = (activesheet.range("j" & rows.count).end(xlup).row)           counter = 0          'paste values 15 times          while counter < 15              'if 2             if browfin1 > (trowfin + counter)                     range("j" & browfin1).value = dblsku                    range("k" & browfin1).value = strdesc                    range("l" & browfin1).value = strtype               elseif browfin1 < (trowfin + counter)                     range("j" & (trowfin + counter)).value = dblsku                    range("k" & (trowfin + counter)).value = strdesc                    range("l" & (trowfin + counter)).value = strtype              else                     range("j" & (trowfin + counter)).value = dblsku                    range("k" & (trowfin + counter)).value = strdesc                    range("l" & (trowfin + counter)).value = strtype              end if          'loop paste wip 15 times         loop               trowfin = trowfin + 1              counter = 0      'if cell (h...) not wip     else          trowfin = trowfin + 1      'if 1     end if    'loop 1 loop  end sub 

your previous code looked like:

  else     range("j" & (trowfin + counter)).value = dblsku     range("k" & (trowfin + counter)).value = strdesc     range("l" & (trowfin + counter)).value = strtype      counter = counter + 1   'if 2   end if loop 

you should instead:

  else     range("j" & (trowfin + counter)).value = dblsku     range("k" & (trowfin + counter)).value = strdesc     range("l" & (trowfin + counter)).value = strtype    'if 2   end if   counter = counter + 1 loop 

your current code has increment inside else means there chance not hit when loop executes. if happens, loop go on infinitely, crashing excel or causing code interruption.

if want loop based on counter, need ensure counter reach exit condition in non-infinite length of time.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -