excel vba - Loop finishing with error -


i need each row has phrase " total" in it, insert rows above , below it, format other cells in , around same row, remove phrase " total" cell, , repeat process other rows in report.

the macro i've developed, once it's found , replaced of instances of " total", run-time error '91': object variable or block variable not set.

i finish loop without ending error has executed on multiple sheets. here meat of code:

'employersummariesaddedforregionsontabs macro dim foundcell range, lastcell range dim firstaddr string range("d3:d3000")     range("d3").select     set lastcell = .cells(.cells.count) end set foundcell = range("d1:d3000").find(what:=" total", after:=lastcell, lookin:=xlvalues, lookat:=xlpart, _     searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:=false, searchformat:=false) if not foundcell nothing     firstaddr = foundcell.address end if until foundcell nothing     set foundcell = range("d1:d3000").findnext(after:=foundcell)      columns("d:d").select     selection.find(what:=" total", after:=activecell, lookin:=xlvalues, _     lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:=false, searchformat:=false).activate     activecell.replace what:="total", replacement:="", lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, _     searchformat:=false, replaceformat:=false     activecell.rows("1:1").entirerow.select     activecell.activate     application.cutcopymode = false     selection.insert shift:=xldown     activecell.offset(3, 0).rows("1:1").entirerow.select     selection.insert shift:=xldown     .     .     .     if foundcell.address = firstaddr         exit     end if loop range("a1").select end sub 

there 2 steps creating object variable. first must declare object variable. error occurs because didn't set object correctly quite same null refrence exception if have programming experience. ran code , seems doesn't @ all! not error! assume error must because of somewhere else in code. way lines replace total in active worksheet nothing:

cells.replace what:=" total", replacement:="", lookat:=xlpart, _         searchorder:=xlbyrows, matchcase:=false, searchformat:=false, _         replaceformat:=false 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

how to receive file in java(servlet/jsp) -