vba - Excel Do While Find -


below code uses .find function in excel find location dodcell appears in sheet2 , add reecell column 18 in sheet2 sheet1. suppose loop based on how many times finds strsearch in rrange.

but, running once , stops, think there mistake in "do while loop" can't seen fix it.

any thoughts?

so after fixing errors pointed out in code have revised sub. think have addressed loop issue, know program running once , freezing excel , need restart excel. think have created infinite loop don't know how fix ideas?

     sub addnumber()     'used add ree value dod projects     dim ssht worksheet, dsht worksheet     dim lastrow integer     dim firstaddress string     dim strsearch string     dim reecell range, dodcell range, arange range, rrange range, aarange range     dim hold1cell range, holdcell range, lastcell range     set ssht = worksheets("sheet1")     set dsht = worksheets("sheet2")     set rrange = ssht.columns(18)     set arange = ssht.columns(1)     set aarange = dsht.columns(1)     lastrow = ssht.range("a" & rows.count).end(xlup).row     strsearch = "2*"

    set dodcell = rrange.find(what:=strsearch, lookin:=xlvalues, _                     lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, _                     matchcase:=false, searchformat:=false)     'if dodcell holds value enter loop     if not dodcell nothing         'set lastcell dodcell         firstaddress = dodcell.address                             'set reecell value of ree number                     set reecell = dodcell.offset(0, -17)                     'set holdcell cell holds dod number in "sheet2"                     set holdcell = aarange.find(what:=dodcell, lookin:=xlvalues, _                                     lookat:=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, _                                     matchcase:=false, searchformat:=false)                     'set hold1cell location ree value should                     set hold1cell = holdcell.offset(0, 9)                     'give hold1cell ree # reecell                     hold1cell = reecell.value                     set dodcell = rrange.findnext(dodcell)          loop while not dodcell nothing , dodcell.address <> firstaddress     end if end sub 

i think while loop may working correctly. looks problem code alters cell contents not within loop well. set dodcell, change value of based on find, , loop find next dodcell, , address of (set dodcell = rrange.findnext, etc.), exit loop , sub.

try moving of other code loop , see if expected results.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -