Excel VBA - Loop through a column of cells and search for each cell value in the workbook -


i need create macro loops through list of selected cells containing strings , takes each string , searches entire workbook string. if string found, sub should exit , found string should selected otherwise move on next string found until end of list.

when run code sub not exit when string in list found , not go cell.

option explicit  dim sheetcount integer dim datatofind  sub button1_click()  find_file  end sub  private sub find_file() dim c range dim counter integer dim currentsheet integer dim notfound boolean notfound = true  each c in selection.cells     on error resume next     currentsheet = activesheet.index     datatofind = strconv(c.value, vblowercase)     if datatofind = "" exit sub     sheetcount = activeworkbook.sheets.count     if iserror(cdbl(datatofind)) = false datatofind = cdbl(datatofind)     counter = 1 sheetcount         sheets(counter).activate         cells.find(what:=datatofind, after:=activecell, lookin:=xlvalues, lookat _         :=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:= _         false, searchformat:=false).activate         if instr(1, strconv(activecell.value, vblowercase), datatofind)             notfound = false             sheets(counter).activate             range("datatofind").select             exit         end if     next counter     if notfound = true         msgbox ("value not found")         sheets(counter).activate     else         exit sub     end if next c end sub 

any appreciated!

if code made different, not change dramatic code

public sub find_file() dim c range dim counter integer dim currentsheet integer dim notfound boolean dim datatofind string dim sheetcount integer dim cellfound range dim celltofind range dim originalsheet worksheet  notfound = true set originalsheet = activesheet each c in selection.cells     on error resume next     currentsheet = activesheet.index     set celltofind = c     datatofind = strconv(c.value, vblowercase)     if datatofind = "" exit sub     sheetcount = activeworkbook.sheets.count     if iserror(cdbl(datatofind)) = false datatofind = cdbl(datatofind)     counter = 1 sheetcount         sheets(counter).activate         set cellfound = cells.find(what:=datatofind, after:=activecell, lookin:=xlvalues, lookat _         :=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:= _         false, searchformat:=false)         if not cellfound nothing             if cellfound.address <> celltofind.address , _                cellfound.parent.name <> celltofind.parent.name                 notfound = false                 cellfound.activate                 goto worksend             end if         end if     next counter next c worksend:     if notfound = true         originalsheet.activate         msgbox ("value not found")      end if  end sub 

i hope understand ...


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -