vba - How to filter and fill visible cell without 1004 error -


i'm trying filter column specified keywords fill text in visible cell of column b using "sub runthis" once keyword not match of rows error1004 appear.

could please suggest me fix ?

thank much,

my cross-posting http://www.excelforum.com/showthread.php?t=1085681&p=4088366 http://www.ozgrid.com/forum/showthread.php?t=195012

public lastrow long  sub runthis()      lastrow = activecell.specialcells(xlcelltypelastcell).row       'suite1      'suite2      'suite3      'suite4      'suite5     suite6       'suite7      'suite8      'suite9      'suite10      'suite11   end sub       '==============================find===suite6================== sub suite6()      on error goto next0       '============search keyword 1 2     activesheet.range("a:a").autofilter field:=1, criteria1:= _      "=*s6r*", operator:=xlor, criteria2:="=*suite6/*"       ' select target column paste     range("d2:d" & lastrow).select      selection.specialcells(xlcelltypevisible).select       ' targettext search     selection.formular1c1 = "suite-6"  next0:      on error goto next2      activesheet.range("a:a").autofilter field:=1, criteria1:= _      "=*suite 6/*", operator:=xlor, criteria2:="=*suite_6/*"       ' select target column paste     range("d2:d" & lastrow).select      selection.specialcells(xlcelltypevisible).select       ' targettext search     selection.formular1c1 = "suite-6"  next2:      on error goto next3      activesheet.range("a:a").autofilter field:=1, criteria1:= _      "=*suite-6/*", operator:=xlor, criteria2:="=*suite6.*"       ' select target column paste     range("d2:d" & lastrow).select      selection.specialcells(xlcelltypevisible).select       ' targettext search     selection.formular1c1 = "suite-6"  next3:      on error goto next4      activesheet.range("a:a").autofilter field:=1, criteria1:= _      "=*suite 6.*", operator:=xlor, criteria2:="=*suite_6.*"       ' select target column paste     range("d2:d" & lastrow).select      selection.specialcells(xlcelltypevisible).select       ' targettext search     selection.formular1c1 = "suite-6"  next4:      on error goto next5      activesheet.range("a:a").autofilter field:=1, criteria1:= _      "=*suite-6.*", operator:=xlor, criteria2:="=*suite-6/*"       ' select target column paste     range("d2:d" & lastrow).select      selection.specialcells(xlcelltypevisible).select       ' targettext search     selection.formular1c1 = "suite-6"  next5:  end sub  

this solve underlying issue without creating messy spaghetty code or leaving filters. bonus think have lower runtime , bit of wits can make loop through suites 1-11.

public lastrow long sub runthis()     lastrow = cells.find(what:="*", searchorder:=xlbyrows, searchdirection:=xlprevious).row      'suite1      'suite2      'suite3      'suite4      'suite5     suite6      'suite7      'suite8      'suite9      'suite10      'suite11   end sub      '==============================find===suite6================== private sub suite6() dim arrayofstrings() string 'arrayofstrings = array("*s6r*", "*suite6/*", "*suite 6/*", "*suite_6/*", "*suite-6/*", _                     "*suite6.*", "*suite 6.*", "*suite_6.*", "*suite-6.*", "*suite-6/*") redim arrayofstrings(9) arrayofstrings(0) = "*s6r*" arrayofstrings(1) = "*suite6/*" arrayofstrings(2) = "*suite_6/*" arrayofstrings(3) = "*suite-6/*" arrayofstrings(4) = "*suite6.*" arrayofstrings(5) = "*suite 6.*" arrayofstrings(6) = "*suite_6.*" arrayofstrings(7) = "*suite-6.*" arrayofstrings(8) = "*suite 6/*" arrayofstrings(9) = "*suite-6/*" columntocheck = "a" 'you looking values in column, weren't you?  = 1 lastrow 'in each of rows     j = lbound(arrayofstrings) ubound(arrayofstrings) 'for each of strings match         if cells(i, columntocheck).value2 arrayofstrings(j) cells(i, columntocheck).value2 = "suite-6" 'if there's match, replace uniform "suite-6"     next j next end sub 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -