vba - FOR loop in Excel - find and replace -
i have following code
sub cleancat() dim integer = 1 50 columns("a").replace what:="cat" & i, replacement:="category" & i, lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false columns("a").replace what:="cat " & i, replacement:="category" & i, lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false columns("a").replace what:="category " & i, replacement:="category" & i, lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false columns("a").replace what:="category" & i, replacement:="category" & i, lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false columns("a").replace what:="cat" & i, replacement:="category" & i, lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false columns("a").replace what:="cat " & i, replacement:="category" & i, lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false columns("a").replace what:="category " & i, replacement:="category" & i, lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false columns("a").replace what:="category" & i, replacement:="category" & i, lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false next end sub
what want loop through every cell in column , replacements shown (i looping through tweets) doesn't replace everything. stuff such something cat 13 here
left
example tweets:
@thisaccount nominate @thataccountfor category 12 #somehashtag cat 12 nominate @thisaccount #somehashtag
any ideas?
another option without number loop. (note: built on @jeeped's answer)
it puts words in array easier updating.
sub cleancat() dim long dim srch() variant dim srchpart variant srch = array("category ", "category", "cat ", "cat") ' make sure in order longest shortest. worksheets("sheet1") .columns("a") = .evaluate("index("'" & a:a,)") .columns("a").replace what:=chr(160), replacement:=chr(32), lookat:=xlpart each srchpart in srch .columns("a").replace what:=srchpart, replacement:="}}}}", lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false next srchpart .columns("a").replace what:="}}}}", replacement:="category", lookat:=xlpart, searchorder:=xlbyrows, matchcase:=false, searchformat:=false, replaceformat:=false end end sub
i stole @jeeped's formula test:
Comments
Post a Comment